You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/07/22 11:37:25 UTC

[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #11457: Single table insert when not used sharding rule for table

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



##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
##########
@@ -410,11 +410,13 @@ private void clearPrevious() throws SQLException {
     @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) {

Review comment:
       @zjcnb Please add some test cases for this change.

##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/parameter/impl/ShardingGeneratedKeyInsertValueParameterRewriter.java
##########
@@ -34,13 +34,15 @@
  */
 @Setter
 public final class ShardingGeneratedKeyInsertValueParameterRewriter implements ParameterRewriter<InsertStatementContext> {
-    
+
     @Override
     public boolean isNeedRewrite(final SQLStatementContext sqlStatementContext) {
-        return sqlStatementContext instanceof InsertStatementContext 
-                && ((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext().isPresent() && ((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext().get().isGenerated();
+        return sqlStatementContext instanceof InsertStatementContext
+                && ((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext().isPresent()
+                && ((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext().get().isGenerated()
+                && !((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext().get().getGeneratedValues().isEmpty();
     }
-    

Review comment:
       @zjcnb Please keep indents consistent with the previous one.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org