From 8f5c12e451cc0ad5e3a9dd54f1fe882acae5b83b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 28 Jan 2007 08:49:23 +0000 Subject: 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 --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 4 ++++ activerecord/test/finder_test.rb | 6 ++++++ 3 files changed, 12 insertions(+) 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 -- cgit v1.2.3