camertron / scuttle-rb

A library for transforming raw SQL statements into ActiveRecord/Arel queries. Ruby wrapper and tests for scuttle-java.
86 stars 2 forks source link

Support BINARY String Comparison #3

Open lardcanoe opened 8 years ago

lardcanoe commented 8 years ago

WHERE posts.author = BINARY ' Mark Twain '

Notice the strings. MySQL string comparison ignores whitespace so you need to add BINARY to force it. Wondering if this is something you can do with your tool.

camertron commented 8 years ago

Ok, I can look into supporting this @lardcanoe. Do you know what the corresponding Arel expression looks like? I've never seen BINARY before.

lardcanoe commented 8 years ago

Something like: Post.where(Arel::Nodes::Bin.new(Arel::Nodes::Equality.new(Post[field], value)))

This will actually create "WHERE BINARY field = value" which is the correct way, though what i put in the original is also a valid format in mysql.

camertron commented 8 years ago

@lardcanoe I did a little poking around and it looks like the SQL parser Scuttle uses doesn't currently recognize the BINARY keyword. Adding support for it is going to be the first step towards a fix. I don't have a ton of free time, but I'll keep this issue on the backburner.