Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'viking/generated-keys'

  • Loading branch information...
commit 66bd1637f62af355e57de09682cae528d5ab2f28 2 parents 468f045 + 919e26a
@jeremyevans authored
Showing with 18 additions and 1 deletion.
  1. +14 −1 lib/sequel/adapters/jdbc.rb
  2. +4 −0 lib/sequel/adapters/jdbc/mysql.rb
View
15 lib/sequel/adapters/jdbc.rb
@@ -190,7 +190,13 @@ def execute(sql, opts={}, &block)
when :ddl
log_yield(sql){stmt.execute(sql)}
when :insert
- log_yield(sql){stmt.executeUpdate(sql)}
+ log_yield(sql) do
+ if requires_return_generated_keys?
+ stmt.executeUpdate(sql, JavaSQL::Statement.RETURN_GENERATED_KEYS)
+ else
+ stmt.executeUpdate(sql)
+ end
+ end
last_insert_id(conn, opts.merge(:stmt=>stmt))
else
log_yield(sql){stmt.executeUpdate(sql)}
@@ -443,6 +449,13 @@ def schema_parse_table(table, opts={})
def transaction_statement_object(conn)
conn.createStatement
end
+
+ # This method determines whether or not to add
+ # Statement.RETURN_GENERATED_KEYS as an argument when inserting rows.
+ # Sub-adapters that require this should override this method.
+ def requires_return_generated_keys?
+ false
+ end
end
class Dataset < Sequel::Dataset
View
4 lib/sequel/adapters/jdbc/mysql.rb
@@ -48,6 +48,10 @@ def last_insert_id(conn, opts={})
end
end
end
+
+ def requires_return_generated_keys?
+ true
+ end
end
# Dataset class for MySQL datasets accessed via JDBC.
Please sign in to comment.
Something went wrong with that request. Please try again.