Skip to content
Snippets Groups Projects
Commit 64a47e8d authored by Henrique Varella Ehrenfried's avatar Henrique Varella Ehrenfried
Browse files

Implement exec_insert method

parent 4b6152f6
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,7 @@ monetdb/database_statements.rb ...@@ -41,7 +41,7 @@ monetdb/database_statements.rb
|- select_rows (*) |- select_rows (*)
|- execute (!) - OK |- execute (!) - OK
|- exec_query (!) - OK Just without cache. We need to implement this later |- exec_query (!) - OK Just without cache. We need to implement this later
|- exec_insert (!) |- exec_insert (!) - OK
|- exec_delete (!) |- exec_delete (!)
|- truncate (!) |- truncate (!)
|- exec_update (!) |- exec_update (!)
......
...@@ -27,7 +27,7 @@ module ActiveRecord ...@@ -27,7 +27,7 @@ module ActiveRecord
# Executes +sql+ statement in the context of this connection using # Executes +sql+ statement in the context of this connection using
# +binds+ as the bind substitutes. +name+ is logged along with # +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement. # the executed +sql+ statement.
def exec_query(sql, name = 'SQL', binds = []) # def exec_query(sql, name = 'SQL', binds = [])
execute_and_clear(sql, name, binds) do |result| execute_and_clear(sql, name, binds) do |result|
types = {} types = {}
fields = result.fields fields = result.fields
...@@ -44,6 +44,17 @@ module ActiveRecord ...@@ -44,6 +44,17 @@ module ActiveRecord
# +binds+ as the bind substitutes. +name+ is logged along with # +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement. # the executed +sql+ statement.
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
val = exec_query(sql, name, binds)
if pk
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
end
exec_query("SELECT currval('#{sequence_name}')", 'SQL')
else
val
end
end end
# Executes delete +sql+ statement in the context of this connection using # Executes delete +sql+ statement in the context of this connection using
......
...@@ -300,6 +300,10 @@ module ActiveRecord ...@@ -300,6 +300,10 @@ module ActiveRecord
def native_database_types def native_database_types
NATIVE_DATABASE_TYPES NATIVE_DATABASE_TYPES
end end
def extract_table_ref_from_insert_sql(sql) # :nodoc:
sql[/into\s+([^\(]*).*values\s*\(/im]
$1.strip if $1
end
end end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment