Sha256: 01c7770ce84e7b00291abcfeea91c4f019644a8956b0dac9f0b7a5fdeec3f743

Contents?: true

Size: 1015 Bytes

Versions: 15

Compression:

Stored size: 1015 Bytes

Contents

module Arel
  module Visitors
    class SQLServer
      def make_Fetch_Possible_And_Deterministic o
        return if o.limit.nil? && o.offset.nil?
        t = table_From_Statement o
        pk = primary_Key_From_Table t
        return unless pk
        if o.orders.empty?
          # Prefer deterministic vs a simple `(SELECT NULL)` expr.
          # CPK
          #o.orders = [pk.asc]
          o.orders = pk.map {|a_pk| a_pk.asc}
        end
      end

      def primary_Key_From_Table t
        return unless t
        column_name = @connection.schema_cache.primary_keys(t.name) ||
          @connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)

        # CPK
        # column_name ? t[column_name] : nil
        case column_name
          when Array
            column_name.map do |name|
              t[name]
            end
          when NilClass
            nil
          else
            [t[column_name]]
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
composite_primary_keys-11.0.3 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.2 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-10.0.5 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.1 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.0 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-10.0.4 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-10.0.3 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.0.rc1 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.0.beta4 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.0.beta3 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.0.beta2 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-11.0.0.beta1 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-10.0.2 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-10.0.1 lib/composite_primary_keys/arel/sqlserver.rb
composite_primary_keys-10.0.0 lib/composite_primary_keys/arel/sqlserver.rb