aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-13 10:41:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-14 13:37:39 -0700
commit8571facea3b51717b3c57c50b2deae5dbf997c6e (patch)
tree7641f3559c3f5add085c7574f58a4ecc070b0f94 /activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
parent4893170da20eee28c016408a0f72f1996343a048 (diff)
downloadrails-8571facea3b51717b3c57c50b2deae5dbf997c6e.tar.gz
rails-8571facea3b51717b3c57c50b2deae5dbf997c6e.tar.bz2
rails-8571facea3b51717b3c57c50b2deae5dbf997c6e.zip
insert statements are prepared, but values are not escaped properly
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index a3082b8f01..6d9b5c7b32 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -56,8 +56,17 @@ module ActiveRecord
end
# Returns the last auto-generated ID from the affected table.
- def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
- insert_sql(sql, name, pk, id_value, sequence_name)
+ #
+ # +id_value+ will be returned unless the value is nil, in
+ # which case the database will attempt to calculate the last inserted
+ # id and return that value.
+ #
+ # If the next id was calculated in advance (as in Oracle), it should be
+ # passed in as +id_value+.
+ def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
+ sql, binds = sql_for_insert(sql, pk, id_value, sequence_name, binds)
+ value = exec_insert(sql, name, binds)
+ id_value || last_inserted_id(value)
end
# Executes the update statement and returns the number of rows affected.
@@ -364,6 +373,15 @@ module ActiveRecord
end
end
end
+
+ def sql_for_insert(sql, pk, id_value, sequence_name, binds)
+ [sql, binds]
+ end
+
+ def last_inserted_id(result)
+ row = result.rows.first
+ row && row.first
+ end
end
end
end