On Thu, Nov 5, 2009 at 5:37 AM, Matteo Vaccari <
matteo.vaccari@...> wrote:
> You are right. I improved the regexp and updated the ticket with a new
> patch. Now it will treat any character after a backslash as part of
> the string literal: /'(\\.|[^'])*'|"(\\.|[^"])*"/
It's still going to be broken on PostgreSQL if
standard_conforming_strings is on, and potentially other databases too
if they conform to the SQL standard (where backslashes are not
special):
a = 'foo\' AND 'foo.bar ' = a
In standard SQL, 'foo\' and 'foo.bar' are two separate string
literals. Your remove_literal_strings converts it to:
a = foo.bar ' = a
> I agree that parsing SQL correctly with regexps is hopeless. But the
> string literal syntax should be well within the possibilities of a
> finite-state automa. I believe this should work... I'll be happy to
> be refuted :-)
It'll work on some databases and not others, because of the
differences in SQL parsers. On PostgreSQL, whether it works depends
on the standard_conforming_strings setting. You could make it adapter
dependent, I suppose.
Also, in the SQL standard double quotes specify identifiers, not
strings, so remove_literal_strings is a misnomer, since it also
removes quoted identifiers. Whether backslashes are allowed and how
they are handled inside quoted identifiers is another thing that is
going to vary depending on the database used.
Maybe since ActiveRecord is getting a major bump to 3.0, it's time to
break backwards compatibility and use a different .find hash key for
preloaded includes (which use separate queries) vs. regular includes
(which use joins). That would avoid the issue of scanning strings
looking for whether or not tables are referenced in order to decide
whether to preload them.
Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to
rubyonrails-core@...
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en-~----------~----~----~----~------~----~------~--~---