vertx-rx
vertx-rx copied to clipboard
updateResult.getKeys doesn't produce expected value.
I am doing an insert into an oracle table. The insert generates a number primary id based on a sequence.
I am trying to get the generated key out of the insert with the following code.
[ oracle.rxGetConnection().flatMap(conn -> conn
.rxUpdateWithParams(mySqlInsertStatement, new JsonArray().add(day))
.doFinally(conn::close)
).subscribe(updateResult ->
updateResult.getKeys().forEach( k -> System.out.println(k))
); ]
The above code works and inserts a row. However, rather than getting a number associated with the primary id, I get a random string like this: AAJGxMAAuAAG7oTAAB.
Am i doing something wrong? The updateResult.getKeys() documentation says it returns the generated keys. Any help would be appreciated.
I should note, I am using vertx-rx-java2 and vertx-jdbc-client version 3.6.3
Oh I just realized its pulling the rowid. Is there a way to get the generated primary key number value besides re-querying the table?
cc @pmlopes do you have an opinion on @jonathon-eastman last comment ?
Oracle returns rowid when you ask for generated keys but did not specify the column indexes.
Before invoking executeUpdate, set the options on the SQLConnection: https://vertx.io/docs/apidocs/io/vertx/ext/sql/SQLConnection.html#setOptions-io.vertx.ext.sql.SQLOptions-
Make sure to provide column indexes in the options: https://vertx.io/docs/apidocs/io/vertx/ext/sql/SQLOptions.html#setAutoGeneratedKeysIndexes-io.vertx.core.json.JsonArray-