oracle / oracle-r2dbc

R2DBC Driver for Oracle Database
https://oracle.com
Other
193 stars 40 forks source link

Oracle doesn't throw error when there is missing permission for the sequence while insertion #149

Open rathoreamrsingh opened 6 days ago

rathoreamrsingh commented 6 days ago

Steps to reproduce:

  1. Create a table with sequence for ID in it.
  2. Create different user.
  3. Grant Select permission for the table to this newly created user but don't grant select permission on sequence.
  4. Insert data to the table using below method. DatabaseClient dbclient = getDbClient(); Flux<? extends Result> flux = dbclient.inConnectionMany(connection -> { Statement statement = connection.createStatement(insertStatement); bindData(recordsToSave, statement); return Flux.from(statement.execute()) .doOnNext(data -> { log.info(data); }) .doOnError(data -> { log.error(data); }); });

This results in OracleResultImpl$BatchUpdateErrorResult which comes under doOnNext rather than doOnError.

The expectation is error should be in error stream doOnError but it is coming as data in doOnNext stream.

Please suggest how to resolve this issue or can be caught in proper manner.

Michael-A-McMahon commented 5 days ago

I can appreciate the confusion here: We might expect the Statement.execute() Publisher to emit onError when that statement fails. This is actually not what the Publisher is specified to do. The Publisher is specified to emit Result objects, and a Result may represent a database error.

For a batch update statement, you can add an operator which maps each Result to the count of rows updated by each set of bind values in your batch:

Flux.from(statement.execute())
  .flatMap(Result::getRowsUpdated)

The getRowsUpdated method will return a Publisher that emits the error to onError.

Hope this helps. Please let me know.