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:25:59 UTC

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

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



##########
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:
       ```
   create table t_config (
     config_name varchar(100) primary key,
     config_value varchar(100)
   );
   insert into t_config (config_name, config_value) values ('key1', 'value1');
   ```
   I am curious what result MySQL or PostgreSQL returns in this case?




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