diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-09 13:53:46 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-09 13:53:57 -0700 |
commit | 73ff6797ef3e6fd0a3ee4b860061cf6869fe835d (patch) | |
tree | 85b21ccac375a0a031cab3ccbb2121ed2819bcca /activerecord/lib | |
parent | c56f4b272d54bcca1978067a1fa8c78bdb3ab516 (diff) | |
download | rails-73ff6797ef3e6fd0a3ee4b860061cf6869fe835d.tar.gz rails-73ff6797ef3e6fd0a3ee4b860061cf6869fe835d.tar.bz2 rails-73ff6797ef3e6fd0a3ee4b860061cf6869fe835d.zip |
use a null byte as a bind parameter substitute as it is not allowed in normal SQL. fixes #411, #417
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 11 |
2 files changed, 9 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 3045e30407..b3eb23bbb3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -6,15 +6,7 @@ module ActiveRecord # Returns an array of record hashes with the column names as keys and # column values as values. def select_all(sql, name = nil, binds = []) - if supports_statement_cache? - select(sql, name, binds) - else - return select(sql, name) if binds.empty? - binds = binds.dup - select sql.gsub('?') { - quote(*binds.shift.reverse) - }, name - end + select(sql, name, binds) end # Returns a record hash with the column names as keys and column values diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 8af22fe9f5..ac2da73a84 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -184,6 +184,10 @@ module ActiveRecord QUOTED_FALSE end + def substitute_at(column, index) + Arel.sql "\0" + end + # REFERENTIAL INTEGRITY ==================================== def disable_referential_integrity(&block) #:nodoc: @@ -292,14 +296,14 @@ module ActiveRecord binds = binds.dup # Pretend to support bind parameters - execute sql.gsub('?') { quote(*binds.shift.reverse) }, name + execute sql.gsub("\0") { quote(*binds.shift.reverse) }, name end def exec_delete(sql, name, binds) binds = binds.dup # Pretend to support bind parameters - execute sql.gsub('?') { quote(*binds.shift.reverse) }, name + execute sql.gsub("\0") { quote(*binds.shift.reverse) }, name @connection.affected_rows end alias :exec_update :exec_delete @@ -646,7 +650,8 @@ module ActiveRecord # Returns an array of record hashes with the column names as keys and # column values as values. def select(sql, name = nil, binds = []) - exec_query(sql, name, binds).to_a + binds = binds.dup + exec_query(sql.gsub("\0") { quote(*binds.shift.reverse) }, name).to_a end def exec_query(sql, name = 'SQL', binds = []) |