We sorted this out over IM: In short '^' matches new lines in Ruby so we switched to using '\A'.
The Ruby on Rails ActiveRecord test suite assumes "execute" can handle SELECTs as well. Is there something we can do fix the ActiveRecord test suite in Rails and submit patches for it? I'm sure we could exert some pressure to get them committed. :-) On 6/29/07, Ola Bini <[EMAIL PROTECTED]> wrote: > Jon Tirsen wrote: > > We're having a lot of trouble with the way _execute selects whether to > > use update or query. > > > > Here's the code in the postgres adapter: > > def _execute(sql, name = nil) > > case sql.strip > > when /^(select|show)/i: > > @connection.execute_query(sql) > > else > > @connection.execute_update(sql) > > end > > end > > > > Executing SQL that looks something like: "UPDATE blah SET \"name\" = > > '\nshow'" would cause the execute_query method to be used even if it's > > actually an update. (This is not actual SQL but we hit something like > > this in production, I've reduced it *significantly* for clarity.) > > > > I'm trying to understand why "select" can't just call "execute_query" > > directly. Using regexps to determine whether it's a select or an > > update is asking for trouble. > > > > Could someone clarify this for me and suggest a way forward that is > > not as fragile as the current approach. > > > > Cheers, > > Jon > > > > One: your example is flawed. Notice the fact that our regexp actually > contains an anchor, so we only look at statements BEGINNING with select > or show. That shouldn't match your update. > > Second, we need to have every SQL go through execute, since that's the > way AR requires us to do it. (Most C adapters don't make any distinction > between updating and querying. You could argue that the JDBC API is a > little bit strange at this point.) But fact remains, doing execute_query > from select wouldn't solve anything, since most people use execute > directly for doing all kinds of SQL, and it would break parts of Rails > that alias execute to do things. > > I know this is brittle, but I don't see a good way of working around it > for now. > > Could you provide an example that actually fails, btw? > > -- > Ola Bini (http://ola-bini.blogspot.com) > JRuby Core Developer > Developer, ThoughtWorks Studios (http://studios.thoughtworks.com) > > "Yields falsehood when quined" yields falsehood when quined. > > > _______________________________________________ > Jruby-extras-devel mailing list > [email protected] > http://rubyforge.org/mailman/listinfo/jruby-extras-devel > _______________________________________________ Jruby-extras-devel mailing list [email protected] http://rubyforge.org/mailman/listinfo/jruby-extras-devel
