Sha256: 86ee91ba7515e057bd43afd6ca5b20c66772c3a1de8d7823b327ee9d5f287907

Contents?: true

Size: 885 Bytes

Versions: 2

Compression:

Stored size: 885 Bytes

Contents

# This adds the method to find the primary key for the schema dumper so that
# the schema will correctly define the primary key. Need to get this into the
# real adapter obviously, though the project seems almost dead.
module MockedFixtures
  module ConnectionAdapters
    module SQLServerAdapter
      
      # Returns a table's primary key and belonging sequence (not applicable to SQL server).
      def pk_and_sequence_for(table_name)
        @connection["AutoCommit"] = false
        keys = []
        execute("EXEC sp_helpindex '#{table_name}'") do |handle|
          if handle.column_info.any?
            pk_index = handle.detect {|index| index[1] =~ /primary key/ }
            keys << pk_index[2] if pk_index
          end
        end
        keys.length == 1 ? [keys.first, nil] : nil
      ensure
        @connection["AutoCommit"] = true
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mocked_fixtures-0.1.0 lib/mocked_fixtures/connection_adapters/sqlserver_adapter.rb
mocked_fixtures-0.2.0 lib/mocked_fixtures/connection_adapters/sqlserver_adapter.rb