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/04/19 13:52:32 UTC

[GitHub] [shardingsphere] TeslaCN commented on a change in pull request #10132: Get generated key only if column type is integer

TeslaCN commented on a change in pull request #10132:
URL: https://github.com/apache/shardingsphere/pull/10132#discussion_r615867797



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
##########
@@ -85,7 +86,18 @@ private QueryResult createQueryResult(final ResultSet resultSet, final Connectio
     
     private long getGeneratedKey(final Statement statement) throws SQLException {
         ResultSet resultSet = statement.getGeneratedKeys();
-        return resultSet.next() ? resultSet.getLong(1) : 0L;
+        return resultSet.next() ? getGeneratedKeyIfInteger(resultSet) : 0L;
+    }
+    
+    private long getGeneratedKeyIfInteger(final ResultSet resultSet) throws SQLException {
+        switch (resultSet.getMetaData().getColumnType(1)) {
+            case Types.SMALLINT:
+            case Types.INTEGER:

Review comment:
       ## PostgreSQL
   
   I have captured the packets and found the following SQL:
   ```
   PostgreSQL
       Type: Parse
       Length: 96
       Statement: 
       Query: insert into t_config_0 (config_name, config_value) values ('key2', 'value2')\nRETURNING *
       Parameters: 0
   ```
   It returned what we inserted.




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

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