Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Possible error
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Niels Jansen  
View profile  
 More options Mar 7 2012, 10:13 am
From: Niels Jansen <nielsjanse...@gmail.com>
Date: Wed, 7 Mar 2012 07:13:40 -0800 (PST)
Local: Wed, Mar 7 2012 10:13 am
Subject: Possible error
Hi

I am using: rails 3.012, tiny_tds 0.5.1 and activerecord-sqlserver-
adapter 3.0.19.

I want to be able to sort the address table using the following sql
query:

select * from addresses order by case when ended_on is null then 0
else 1 end, ended_on desc

This will give me a sorted list where the addresses that have ended_on
NULL comes first and the rest comes in descending order by ended_on.

However, when I try creating this scope

scope :my_order, :order => "case when ended_on is null then 0 else 1
end, ended_on desc"

and typing Address.limit(10).my_order into a console I get this error:

ActiveRecord::StatementInvalid: TinyTds::Error: Incorrect syntax near
the keyword 'ASC'.: SELECT TOP (10) [addresses].* FROM [addresses]
ORDER BY case ASC, ended_on DESC

I am guessing that the error might be in whatever code that takes
input from rails and makes that into sql. It seems to cut off most of
the first statement and inserting an ASC instead (btw there is no case
column in the addresses table). Does that occur in the sqlserver-
adapter or do I need to ask about this problem somewhere else?

- Niels


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Collins  
View profile  
 More options Mar 7 2012, 10:19 am
From: Ken Collins <k...@metaskills.net>
Date: Wed, 7 Mar 2012 10:19:33 -0500
Local: Wed, Mar 7 2012 10:19 am
Subject: Re: [RailsSQLServer] Possible error

Have you searched on the Github issues for things like "order"? This ticket comes to the top and seems related.

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pul...

It explains about how the adapter/visitor has to work with orders and the need for using an Arel sql literal. Because of that and the various tickets, we have an extensive order test too.

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blo...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Niels Jansen  
View profile  
 More options Mar 8 2012, 6:50 am
From: Niels Jansen <nielsjanse...@gmail.com>
Date: Thu, 8 Mar 2012 03:50:35 -0800 (PST)
Local: Thurs, Mar 8 2012 6:50 am
Subject: Re: Possible error
*duh* I should have searched github, not just google. However, I
wasn't sure what kind of problem I was having. Now at least, I know it
is in rails-sqlserver-adapter.

I see that is has been addressed, in 3.1.5. However, I am on 3.0.19
(since I am using rails 3.0, I am upgrading from 2.3 and didn't want
to upgrade directly to 3.2). Can the fix be applied to 3.0.19?

Also, if I define the order like this:

Arel::Nodes::Ordering.new(Arel.sql('CASE WHEN ended_on IS NULL THEN 1
ELSE 0 END'))

it works... however, this is also valid sql and doesn't work:

Arel::Nodes::Ordering.new(Arel.sql('CASE WHEN ended_on IS NULL THEN 1
ELSE 0 END, ended_on DESC'))

This last ordering spits out the following error:

SELECT [addresses].* FROM [addresses] ORDER BY CASE WHEN ended_on IS
NULL THEN 1 ELSE 0 END, ended_on DESC ASC

Seems that it throws and extra ASC in the for good measure, which
bungles the whole thing... how to I prevent it from doing that? I want
to do this:

has_many :addresses, :order =>
Arel::Nodes::Ordering.new(Arel.sql('CASE WHEN ended_on IS NULL THEN 1
ELSE 0 END, ended_on DESC'))

Is there a workaround?

I appreciate your help!

- Niels

On Mar 7, 4:19 pm, Ken Collins <k...@metaskills.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Collins  
View profile  
 More options Mar 8 2012, 7:49 am
From: Ken Collins <k...@metaskills.net>
Date: Thu, 8 Mar 2012 07:49:51 -0500
Local: Thurs, Mar 8 2012 7:49 am
Subject: Re: [RailsSQLServer] Possible error

Review the ticket and the commits. You would have to monkey patch the Arel visitor as I did in the fix commits and then use an Arel sql literal wrapper as the comment/tests show.

 - Ken

On Mar 8, 2012, at 6:50 AM, Niels Jansen wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »