
:conditions in query does not fill in more than first bind-value
Reported by Sindre Aarsaether | February 22nd, 2009 @ 04:18 PM
When you supply raw conditions to #all or #first it does not fill in more than the first bind-value. This
class User
include DataMapper::Resource
property :id, Serial
property :login, String
property :name, String
end
User.all(:conditions => ["id = ? OR login = ? OR name = ?",1,'admin','john'])
-> SELECT ... FROM users WHERE id = 1 OR login = NULL OR name = NULL
The bug probably surfaced after this commit: http://github.com/datamapper/dm-... but I cannot confirm it right now (not at my workstation).
Comments and changes to this ticket
-
Dan Kubb (dkubb) February 23rd, 2009 @ 12:44 AM
- State changed from unconfirmed to resolved
(from [3373ec7e144b46e524a6558e8019653ab9e9e29f]) Fixed bind value handling for raw conditions in WHERE clause generation
[#805 state:resolved] http://github.com/datamapper/dm-...
-
Sindre Aarsaether February 24th, 2009 @ 03:37 PM
- State changed from resolved to hold
This is still broken (in another way)...
Item.first(:conditions => ["id = ? OR id = ?",1,2]) ~ (mysql_errno=1064, sql_state=42000) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? OR id = ? ORDER BY
id
LIMIT 1' at line 1 Query: SELECTid
,name
,user_id
FROMitems
WHERE id = ? OR id = ? ORDER BYid
LIMIT 1 MysqlError: (mysql_errno=1064, sql_state=42000) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? OR id = ? ORDER BYid
LIMIT 1' at line 1I see that it works now if you pack the arguments in an array like ["id = ? OR id = ?",[1,2]] but this is not how it has worked earlier, nor how it should?
-
Dan Kubb (dkubb) February 27th, 2009 @ 01:30 PM
- State changed from hold to resolved
(from [ef03457a387e6404b3adea2de02a6e1b4c683f3e]) Fixed bind values for raw query to be an Array as expected
[#805 state:resolved] http://github.com/datamapper/dm-...
-
Dan Kubb (dkubb) February 27th, 2009 @ 01:50 PM
Attached is a small script that demonstrates the fix.
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Tags
Referenced by
-
805 :conditions in query does not fill in more than first bind-value [#805 state:resolved] http://github.com/datamapper/dm-...
-
805 :conditions in query does not fill in more than first bind-value [#805 state:resolved] http://github.com/datamapper/dm-...