aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-21 16:32:13 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-21 16:32:13 -0700
commit3378d77b044306d6e92f188932d435483af569e3 (patch)
tree473bf27eacd0cf094fd91ae8e31424a67d561740 /activerecord
parent88636f7195fc936421392740f980d17ebe77d701 (diff)
downloadrails-3378d77b044306d6e92f188932d435483af569e3.tar.gz
rails-3378d77b044306d6e92f188932d435483af569e3.tar.bz2
rails-3378d77b044306d6e92f188932d435483af569e3.zip
use prepared statements to fetch the last insert id
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 576450bc3a..5a830a50fb 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -453,7 +453,7 @@ module ActiveRecord
# If a pk is given, fallback to default sequence name.
# Don't fetch last insert id for a table without a pk.
if pk && sequence_name ||= default_sequence_name(table, pk)
- last_insert_id(table, sequence_name)
+ last_insert_id(sequence_name)
end
end
end
@@ -1038,8 +1038,9 @@ module ActiveRecord
end
# Returns the current ID of a table's sequence.
- def last_insert_id(table, sequence_name) #:nodoc:
- Integer(select_value("SELECT currval('#{sequence_name}')"))
+ def last_insert_id(sequence_name) #:nodoc:
+ r = exec_query("SELECT currval($1)", 'SQL', [[nil, sequence_name]])
+ Integer(r.rows.first.first)
end
# Executes a SELECT query and returns the results, performing any data type