[Rails] ActiveRecord: It's not only quoting
David Heinemeier Hansson
david at loudthinking.com
Fri Dec 17 12:57:42 GMT 2004
> First of all I've added a small hack to the value_list method in class
> Fixture (fixtures.rb): Things that look like an int (/^\d+$/) will be
> converted to an int now and ":00" is appended to all values, that look
> like a timestamp (/\d{4}-\d\d-\d\d \d\d:\d\d/). Otherwise DB2 won't
> accept them.
How would that deal with things like credit card codes such as "0450"?
Otherwise, it sounds fine with these hacks.
> As far as I know the "old" test fixtures will be replaced by "typed"
> ones (YAML) soon, won't they?
In Rails 0.9, the yml (and csv) fixtures are now the recommended use
for fixtures. The generators create yml files, so basically the old
test fixtures are deprecated. If you need to make the AR unit tests
pass, please do convert all the AR fixtures to yml. I'd be fine with
the fact that new adapters doesn't work with the deprecated fixture
style.
> But there are more difficult things: The find method(s) in
> ActiveRecord::Base don't work properly because the sanitize method
> still does not quote id values correctly. In my opinion all find
> methods that expect an int or a list of ints should convert their
> arguments using to_i before doing anything. Would that cause any
> problems?
Yeah, as others have mentioned, we want to allow string-based primary
keys. But at the time of find, we could already know what type the id
SHOULD have (through the column information) and typecast accordingly.
I think that's the way to go.
> Additionally, most of the "SELECT" statements will not work with NULL
> values. In DB2 it's not possible to run a statement like "SELECT * FROM
> x WHERE y = NULL". It has to be "SELECT * FROM x WHERE y IS NULL".
When those statements like this occur? We could look into making
quoted_comma_pair_list aware of nils and use the IS NULL style instead.
> I've found some SQL statements using the "LIMIT" clause. This does not
> exist in DB2 (at least not in Version 7) and it has to be replaced by
> "fetch first <x> rows only". In Oracle I've always used "WHERE ROWNUM <
> x" and I do not know, if Oracle has a "LIMIT" keyword.
There has been some talk about turning the limit clause into something
that could be delegated to the database to figure out. Just like we do
for quoting. I think that's a good idea.
> I think it's not a good idea to clutter the code base with esoteric
> DB2/Oracle/... knowledge. Any suggestions?
As needed, we can start putting more responsibility into the adapters
when there's _no way_ it could work otherwise. We should try to find
other options first, but there's nothing religious about it.
Great work, Maik. It's exciting to see the new adapters move towards
completion.
--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain
More information about the Rails
mailing list