Only used detailed schema introspection when doing a schema dump.

Fixes #3678
This commit is contained in:
Christos Zisopoulos 2011-11-18 18:29:47 +01:00
parent d4119e144a
commit 280b2b725b
2 changed files with 10 additions and 1 deletions

@ -576,6 +576,13 @@ def show_variable(name)
# Returns a table's primary key and belonging sequence.
def pk_and_sequence_for(table)
execute_and_free("DESCRIBE #{quote_table_name(table)}", 'SCHEMA') do |result|
keys = each_hash(result).select { |row| row[:Key] == 'PRI' }.map { |row| row[:Field] }
keys.length == 1 ? [keys.first, nil] : nil
end
end
def detailed_pk_and_sequence_for(table)
sql = <<-SQL
SELECT t.constraint_type, k.column_name
FROM information_schema.table_constraints t

@ -86,7 +86,9 @@ def table(table, stream)
tbl = StringIO.new
# first dump primary key column
if @connection.respond_to?(:pk_and_sequence_for)
if @connection.respond_to?(:detailed_pk_and_sequence_for)
pk, _ = @connection.detailed_pk_and_sequence_for(table)
elsif @connection.respond_to?(:pk_and_sequence_for)
pk, _ = @connection.pk_and_sequence_for(table)
elsif @connection.respond_to?(:primary_key)
pk = @connection.primary_key(table)