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 2022/07/20 06:50:20 UTC

[GitHub] [shardingsphere] yunmengmeng commented on a diff in pull request #18905: fix 18904(#18904)

yunmengmeng commented on code in PR #18905:
URL: https://github.com/apache/shardingsphere/pull/18905#discussion_r925236275


##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ReadwriteSplittingPreparedStatementTest.java:
##########
@@ -92,4 +94,31 @@ public void assertGetGeneratedKeysWithPrimaryKeyIsNull() throws SQLException {
             assertFalse(generatedKeys.next());
         }
     }
+
+    @Test
+    public void assertGetGeneratedKeysWithPrimaryKeyIsNullInTransactional() throws SQLException {
+        try (
+                Connection connection = getReadwriteSplittingDataSource()
+                        .getConnection();
+                PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t_config(id, status) VALUES(?, ?);", Statement.RETURN_GENERATED_KEYS)) {
+            connection.setAutoCommit(false);
+            Object lastIdObject = null;
+            Object idObject = null;
+            for (int i = 1; i <= 3; i++) {
+                preparedStatement.setObject(1, null);
+                preparedStatement.setString(2, "OK");
+                preparedStatement.executeUpdate();
+                ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
+                assertTrue(generatedKeys.next());
+                int columnCount = generatedKeys.getMetaData().getColumnCount();
+                for (int index = 0; index < columnCount; index++) {

Review Comment:
   > Can you remove this loop logic? Just call `generatedKeys.getObject(1)` once.
   
   I saw the previous test case and imitated it.I have changed them now.



-- 
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