Permalink
Browse files

Only used detailed schema introspection when doing a schema dump.

Fixes #3678
  • Loading branch information...
1 parent d4119e1 commit 280b2b725b488ef71556970ee895ccaddc315e0c @christos christos committed Nov 18, 2011
@@ -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)

0 comments on commit 280b2b7

Please sign in to comment.