strongduanmu commented on a change in pull request #11457:
URL: https://github.com/apache/shardingsphere/pull/11457#discussion_r677060422



##########
File path: 
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
##########
@@ -406,15 +406,17 @@ private void clearPrevious() throws SQLException {
         return executionContext.getSqlStatementContext() instanceof 
InsertStatementContext
                 ? ((InsertStatementContext) 
executionContext.getSqlStatementContext()).getGeneratedKeyContext() : 
Optional.empty();
     }
-
+    
     @Override
     public ResultSet getGeneratedKeys() throws SQLException {
         Optional<GeneratedKeyContext> generatedKey = 
findGeneratedKey(executionContext);
-        if (statementOption.isReturnGeneratedKeys() && 
generatedKey.isPresent()) {
+        if (statementOption.isReturnGeneratedKeys() && 
generatedKey.isPresent() && !generatedValues.isEmpty()) {
             return new 
GeneratedKeysResultSet(generatedKey.get().getColumnName(), 
generatedValues.iterator(), this);
         }
-        if (1 == statements.size()) {
-            return statements.iterator().next().getGeneratedKeys();
+        for (PreparedStatement statement : statements) {
+            if (statement.getGeneratedKeys().next()) {
+                return statement.getGeneratedKeys();

Review comment:
       @zjcnb If the user does not configure the key generation strategy, 
should we return all the keys generated by the DB?

##########
File path: 
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
##########
@@ -406,15 +406,17 @@ private void clearPrevious() throws SQLException {
         return executionContext.getSqlStatementContext() instanceof 
InsertStatementContext
                 ? ((InsertStatementContext) 
executionContext.getSqlStatementContext()).getGeneratedKeyContext() : 
Optional.empty();
     }
-
+    
     @Override
     public ResultSet getGeneratedKeys() throws SQLException {

Review comment:
       @zjcnb Please also consider the `getGeneratedKeys` method of 
`ShardingSphereStatement`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to