aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-01-28 08:49:23 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-01-28 08:49:23 +0000
commit8f5c12e451cc0ad5e3a9dd54f1fe882acae5b83b (patch)
treed98ebb0efde8ad18cb84b193bfd907ebb281a6e6
parent799f556fe1795c0c94dd5bf09ca84426e861de33 (diff)
downloadrails-8f5c12e451cc0ad5e3a9dd54f1fe882acae5b83b.tar.gz
rails-8f5c12e451cc0ad5e3a9dd54f1fe882acae5b83b.tar.bz2
rails-8f5c12e451cc0ad5e3a9dd54f1fe882acae5b83b.zip
MySQL: SET SQL_AUTO_IS_NULL=0 so 'where id is null' doesn't select the last inserted id. Closes #6778.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6064 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb4
-rw-r--r--activerecord/test/finder_test.rb6
3 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index cda2262ed4..85b5262994 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* MySQL: SET SQL_AUTO_IS_NULL=0 so 'where id is null' doesn't select the last inserted id. #6778 [Jonathan Viney, timc]
+
* Use Date#to_s(:db) for quoted dates. #7411 [Michael Schoen]
* Don't create instance writer methods for class attributes. Closes #7401 [Rick]
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 08b3c22ec7..842258f1ea 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -388,6 +388,10 @@ module ActiveRecord
@connection.ssl_set(@config[:sslkey], @config[:sslcert], @config[:sslca], @config[:sslcapath], @config[:sslcipher]) if @config[:sslkey]
@connection.real_connect(*@connection_options)
execute("SET NAMES '#{encoding}'") if encoding
+
+ # By default, MySQL 'where id is null' selects the last inserted id.
+ # Turn this off. http://dev.rubyonrails.org/ticket/6778
+ execute("SET SQL_AUTO_IS_NULL=0")
end
def select(sql, name = nil)
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index 1e6e4cf6cd..eb1e4d639c 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -460,6 +460,12 @@ class FinderTest < Test::Unit::TestCase
end
end
+ # http://dev.rubyonrails.org/ticket/6778
+ def test_find_ignores_previously_inserted_record
+ post = Post.create!
+ assert_equal [], Post.find_all_by_id(nil)
+ end
+
def test_find_by_empty_ids
assert_equal [], Post.find([])
end