diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 2509fe0490..5e166defea 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -797,25 +797,17 @@ module ActiveRecord def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) val = exec_query(sql, name, binds) if !use_returning? && pk - if sequence_name - last_insert_id_value(sequence_name) - else + unless sequence_name table_ref = extract_table_ref_from_insert_sql(sql) sequence_name = default_sequence_name(table_ref, pk) return val unless sequence_name - last_insert_id(sequence_name) end + last_insert_id_result(sequence_name) else val end end - def last_inserted_id(result) - return result if result.kind_of?(Integer) - row = result.rows.first - row && row.first - end - # Executes an UPDATE query and returns the number of affected tuples. def update_sql(sql, name = nil) super.cmd_tuples @@ -1406,9 +1398,12 @@ module ActiveRecord Integer(last_insert_id_value(sequence_name)) end - def last_insert_id_value(sequence_name) #:nodoc: - r = exec_query("SELECT currval($1)", 'SQL', [[nil, sequence_name]]) - r.rows.first.first + def last_insert_id_value(sequence_name) + last_insert_id_result(sequence_name).rows.first.first + end + + def last_insert_id_result(sequence_name) #:nodoc: + exec_query("SELECT currval($1)", 'SQL', [[nil, sequence_name]]) end # Executes a SELECT query and returns the results, performing any data type |