This project is archived and is in readonly mode.
Multiline string in 'where' condition produces incorrect SQL
Reported by Valentine Bichkovsky | March 10th, 2010 @ 01:58 PM
This piece of code:
class Asset
...
scope :by_text, lambda {|text|
unless text.blank?
includes(:tags).where(
"(asset_translations.locale = :loc and
(asset_translations.name like :expr or
asset_translations.description like :expr)) or
(tags.name = :name and tags.locale = :loc)",
{:expr => "%#{text}%", :name => text, :loc => I18n.locale.to_s} )
end
}
...
end
produces incorrect SQL in Ruby 1.8.7:Asset.by_text('foo').to_sql => "SELECT
assets.* FROMassets
WHERE ((asset_translations.locale = 'en-US' and \n) AND ( (asset_translations.name like '%foo%' or \n) AND ( asset_translations.description like '%foo%')) or \n) AND ( (tags.name = 'foo' and tags.locale = 'en-US'))"
Works fine in Ruby 1.9.1, or (for Ruby 1.8.7) when line endings
are escaped like that:
scope :by_text, lambda {|text|
unless text.blank?
includes(:tags).where(
"(asset_translations.locale = :loc and \
(asset_translations.name like :expr or \
asset_translations.description like :expr)) or \
(tags.name = :name and tags.locale = :loc)",
{:expr => "%#{text}%", :name => text, :loc => I18n.locale.to_s} )
end
}
BTW, how do I post arbitrarily indented code here?
Comments and changes to this ticket
-
Valentine Bichkovsky March 10th, 2010 @ 01:59 PM
- no changes were found...
-
Rohit Arondekar June 23rd, 2010 @ 03:12 AM
- State changed from new to invalid
If you escape line endings, \n won't be added to the string. At the time 1.9.1 might have escaped line endings automatically but now all 3 rubies (1.9.1, 1.9.2 and 1.8.7) behave in the same manner.
I'm closing this ticket, but if this is still an issue please make a comment to reopen and I'll oblige.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>