Permalink
Browse files

MySQL: SET SQL_AUTO_IS_NULL=0 so 'where id is null' doesn't select th…

…e last inserted id. Closes #6778.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6064 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 799f556 commit 8f5c12e451cc0ad5e3a9dd54f1fe882acae5b83b @jeremy jeremy committed Jan 28, 2007
@@ -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]
@@ -388,6 +388,10 @@ def connect
@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)
@@ -460,6 +460,12 @@ def test_find_by_id_with_conditions_with_or
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

0 comments on commit 8f5c12e

Please sign in to comment.