Skip to content

Commit

Permalink
Fix GH rails#4754. Remove double-quote when using ANSI_QUOTES
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Jan 30, 2012
1 parent 6831ab1 commit 1a1d9e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def pk_and_sequence_for(table)
execute_and_free("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA') do |result|
create_table = each_hash(result).first[:"Create Table"]
if create_table.to_s =~ /PRIMARY KEY\s+\((.+)\)/
keys = $1.split(",").map { |key| key.gsub(/`/, "") }
keys = $1.split(",").map { |key| key.gsub(/[`"]/, "") }
keys.length == 1 ? [keys.first, nil] : nil
else
nil
Expand Down
16 changes: 16 additions & 0 deletions activerecord/test/cases/primary_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,19 @@ def test_set_primary_key_with_no_connection
assert_equal 'foo', model.primary_key
end
end

if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
class PrimaryKeyWithAnsiQuotesTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false

def test_primaery_key_method_with_ansi_quotes
con = ActiveRecord::Base.connection
con.execute("SET SESSION sql_mode='ANSI_QUOTES'")
assert_equal "id", con.primary_key("topics")
ensure
con.reconnect!
end

end
end

0 comments on commit 1a1d9e6

Please sign in to comment.