This is in response to the bug report I opened here:
http://code.google.com/p/ruby-sequel/issues/detail?id=315
In summary:
When passing 1 value to Model.[] on a table with a composite primary
key Sequel performs an erroneous query
class PkTest < Sequel::Model(:pk)
set_primary_key [ :upc, :code ]
end
# MySQL
PkTest['X1234']
> I, [2010-11-15T01:53:59.991449 #21065] INFO -- : (0.000272s) SELECT * FROM
> `pk` WHERE ((`upc` = 88) AND (`code` = 49)) LIMIT 1
SQL Server (maybe others?) raise a type error here.
Model.[] uses Model.primary_key_hash to build the query. This results
in:
PkTest.primary_key_hash 'X1234'
> {:upc=>88, :code=>49}
My patch would change this like so:
PkTest.primary_key_hash 'X1234'
> {:upc=>"X1234", :code=>nil}
Which is similar to the current functionality:
PkTest.primary_key_hash ['X1234']
> {:upc=>"X1234", :code=>nil}
This change would make calls to Model.[] that do not include values
for all of the primary key columns
create an SQL statement that has the where conditions of the missing
columns set to IS NULL.
The alternate is to raise an error if the number of arguments don't
match the number of PK columns, which prevents querying a NULL pk (see
bug report link).
Thoughts?
-Skye
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.