vertx-rx icon indicating copy to clipboard operation
vertx-rx copied to clipboard

updateResult.getKeys doesn't produce expected value.

Open jonathon-eastman opened this issue 6 years ago • 4 comments

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.

jonathon-eastman avatar Mar 11 '19 22:03 jonathon-eastman

I should note, I am using vertx-rx-java2 and vertx-jdbc-client version 3.6.3

jonathon-eastman avatar Mar 11 '19 22:03 jonathon-eastman

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?

jonathon-eastman avatar Mar 11 '19 22:03 jonathon-eastman

cc @pmlopes do you have an opinion on @jonathon-eastman last comment ?

vietj avatar Mar 12 '19 08:03 vietj

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-

tsegismont avatar Mar 12 '19 09:03 tsegismont