File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
lib/active_record/connection_adapters Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -668,7 +668,7 @@ def add_lock!(sql, options)
668668 end
669669 end
670670
671- def recreate_database ( name )
671+ def recreate_database ( name )
672672 # Switch to another database or we'll receive a "Database in use" error message.
673673 existing_database = current_database . to_s
674674 if name . to_s == existing_database
@@ -817,6 +817,21 @@ def remove_index(table_name, options = {})
817817 execute "DROP INDEX #{ table_name } .#{ quote_column_name ( index_name ( table_name , options ) ) } "
818818 end
819819
820+ # Returns a table's primary key and belonging sequence (not applicable to SQL server).
821+ def pk_and_sequence_for ( table_name )
822+ @connection [ "AutoCommit" ] = false
823+ keys = [ ]
824+ execute ( "EXEC sp_helpindex '#{ table_name } '" ) do |handle |
825+ if handle . column_info . any?
826+ pk_index = handle . detect { |index | index [ 1 ] =~ /primary key/ }
827+ keys << pk_index [ 2 ] if pk_index
828+ end
829+ end
830+ keys . length == 1 ? [ keys . first , nil ] : nil
831+ ensure
832+ @connection [ "AutoCommit" ] = true
833+ end
834+
820835 private
821836 def __indexes ( table_name , name = nil )
822837 indexes = [ ]
You can’t perform that action at this time.
0 commit comments