lib/active_record/connection_adapters/fdbsql/schema_statements.rb
# Resets the sequence of a table's primary key to the maximum value.
Resets the sequence of a table's primary key to the maximum value.
Resets the sequence of a table ' s primary key to the maximum value .
def reset_pk_sequence!(table_name, primary_key=nil, sequence_name=nil)
          primary_key, seq_schema, sequence_name = pk_and_sequence_for(table_name, true)
          if primary_key && !sequence_name
            @logger.warn "#{table_name} has primary key #{primary_key} with no sequence" if @logger
          end
          if primary_key && sequence_name
            seq_from_where = "FROM information_schema.sequences "+
                             "WHERE sequence_schema='#{quote_string(seq_schema)}' "+
                             "AND sequence_name='#{quote_string(sequence_name)}'"
            result = select_rows(
              "SELECT COALESCE(MAX(#{quote_column_name(primary_key)} + (SELECT increment #{seq_from_where})), "+
              "       (SELECT minimum_value #{seq_from_where})) "+
              "FROM #{quote_table_name(table_name)}",
              SCHEMA_LOG_NAME
            )
            if result.length == 1
              execute(
                "COMMIT; "+
                "CALL sys.alter_seq_restart('#{quote_string(seq_schema)}', '#{quote_string(sequence_name)}', #{result[0][0]}); "+
                "BEGIN;",
                SCHEMA_LOG_NAME
              )
            else
              @logger.warn "Unable to determin max value for #{table_name}.#{primary_key}" if @logger
            end
          end
        end
def reset_pk_sequence! ( table_name , primary_key = nil , sequence_name = nil ) primary_key , seq_schema , sequence_name = pk_and_sequence_for ( table_name , true ) if primary_key && ! sequence_name @logger . warn "#{table_name} has primary key #{primary_key} with no sequence" if @logger end if primary_key && sequence_name seq_from_where = "FROM information_schema.sequences " + "WHERE sequence_schema='#{quote_string(seq_schema)}' " + "AND sequence_name='#{quote_string(sequence_name)}'" result = select_rows ( "SELECT COALESCE(MAX(#{quote_column_name(primary_key)} + (SELECT increment #{seq_from_where})), " + "       (SELECT minimum_value #{seq_from_where})) " + "FROM #{quote_table_name(table_name)}" , SCHEMA_LOG_NAME ) if result . length == 1 execute ( "COMMIT; " + "CALL sys.alter_seq_restart('#{quote_string(seq_schema)}', '#{quote_string(sequence_name)}', #{result[0][0]}); " + "BEGIN;" , SCHEMA_LOG_NAME ) else @logger . warn "Unable to determin max value for #{table_name}.#{primary_key}" if @logger end end end
Resets the sequence of a table's primary key to the maximum value.
Resets the sequence of a table ' s primary key to the maximum value .
# The COMMIT; BEGIN; can go away when 1) transactional DDL is available 2) There is a better restart/set function
table_name
primary_key
sequence_name