ambition: hard-coded MySQL syntax in WhereProcessor methods
-
Matthew King
- Title changed from Hard-coded MySQL syntax in WhereProcessor methods to ambition: hard-coded MySQL syntax in WhereProcessor methods
-
Chris Wanstrath
- State changed from new to open
I thought RLIKE was MySQL-specific and REGEXP was SQL standard. Am I getting it backwards?
Yes, Ambition was written for MySQL and ActiveRecord. But I don't want it to stay that way. Any help on general compatibility would be great.
So, backticks are a no-go? I don't like them that much, anyway.
-
Matthew King
Here's a patch that adds a quote_column_name facade for the ActiveRecord connection to Processor, which is then used in WhereProcessor#translate.
The patch has no tests, because I can't figure out a way to test without using a live ActiveRecord connnection.
I will gladly add some tests, if someone can give me a clue on how to mock or stub or prestidigitate an AR connection, so that I can access the adapter-specific quoting methods.
-
Matthew King
Regarding REGEXP and SQL standards, I dunno. I haven't been using postgres long, and I have to look everything up anyway. Speaking of which, the PostgreSQL manual has a table showing regex operators:
http://www.postgresql.org/docs/8...
It should be easy to add a clumsy helper method that picks a regex operator based on the AR::Base.connection adapter, but that seems ugly.
-
Chris Wanstrath
I think having database-specific translators maybe the only way. Since that requires some architecture re-thinking, I may take that on later tonight sometime. Suck.
I added the column_name thing. I need to improve to_sql generation -- right now it's not matching the actual SQL called. Note to self.
-
Matthew King
Re: database-specific translators for regexp
How bad of an idea is this?
Monkeypatch each ActiveRecord adapter with regexp-producing methods, then call them in WhereProcessor#process_match3 using:
ActiveRecord::Base.connection.regexp(value)or a suitable helper method.
-
Matthew King
I'm uploading a meaty patch (with tests!) that implements the idea in my last comment. I.e., it monkeypatches the Abstract, MySQL, and PostgreSQL adapters with a method named ambition_regexp. It also adds a method named adapter_regexp to Processor and slightly smartens the rescue clauses in the quoting methods. The results are not as ugly as I had feared.
In where_test.rb, I added contexts for MySQL, PostgreSQL, and an adapter that doesn't get monkeypatched (so I can test the Abstract adapter). It turns out that you can fake a new PostgreSQL connection by passing it strings for args, and you can fake a MySQL connection by overriding its connect method and passing strings for args. This appears to be sufficient to test the helper methods in these classes, namely the quoting.
-
Chris Wanstrath
Do you have AIM or hang out on IRC? I'm doing some refactoring today and want to talk to you about this patch / concept.
-
Matthew King
I usually don't do the chatty things, but I can on weekdays. On weekends, my real boss requests that I keep computer work to a minimum.
-
Chris Wanstrath
- State changed from open to resolved
I took a slightly different approach, but the idea is the same. Should be fixed now:
http://projects.require.errthebl...
The
statementmethod opens the door for future DB-specific stuffs, too (one hopes).
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
