Sha256: e8fb2346b3f53322e5a2af0fa4a5b59d05c8753ff307052a8c0ac1e5f4275a10

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    class PostgreSQLAdapter
      def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
        unless pk
          # Extract the table from the insert sql. Yuck.
          table_ref = extract_table_ref_from_insert_sql(sql)
          pk = primary_key(table_ref) if table_ref
        end

        if pk
          # CPK
          # select_value("#{sql} RETURNING #{quote_column_name(pk)}")
          select_value("#{sql} RETURNING #{quote_column_names(pk)}")
        else
          super
        end
      end
      alias :create :insert

      def sql_for_insert(sql, pk, id_value, sequence_name, binds)
        unless pk
          # Extract the table from the insert sql. Yuck.
          table_ref = extract_table_ref_from_insert_sql(sql)
          pk = primary_key(table_ref) if table_ref
        end

        # CPK
        # sql = "#{sql} RETURNING #{quote_column_name(pk)}" if pk
        sql = "#{sql} RETURNING #{quote_column_names(pk)}" if pk

        [sql, binds]
      end

      # Returns a single value if query returns a single element
      # otherwise returns an array coresponding to the composite keys
      #
      def last_inserted_id(result)
        row = result && result.rows.first
        if Array === row
          row.size == 1 ? row[0] : row
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
composite_primary_keys-7.0.15 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-8.1.1 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.14 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-8.1.0 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.13 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-8.0.0 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.12 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.11 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.10 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.9 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.8 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.7 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.6 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
composite_primary_keys-7.0.5 lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb