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 2019/12/23 01:49:37 UTC

[GitHub] [incubator-shardingsphere] zhegexiaohuozi opened a new issue #3210: ON DUPLICATE KEY UPDATE support incompletely

zhegexiaohuozi opened a new issue #3210: ON DUPLICATE KEY UPDATE support incompletely
URL: https://github.com/apache/incubator-shardingsphere/issues/3210
 
 
   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - Searched open and closed [GitHub issues](https://github.com/apache/incubator-shardingsphere/issues).
   - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more details. 
   If no response **more than 7 days** and we cannot reproduce it on current information, we will **close it**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Which version of ShardingSphere did you use?
   `4.0.0-RC2`
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   `Sharding-JDBC`
   ### Expected behavior
   `INSERT INTO table_a (id,col_1,col_2) VALUES(1,#{bean.val1}, #{bean.val2}) ON DUPLICATE KEY UPDATE col_2 = col_2 + #{bean.val2}`  should execute successfully.
   ### Actual behavior
   got exception
   ```
   org.springframework.jdbc.BadSqlGrammarException: 
   ### Error updating database.  Cause: java.sql.SQLException: No value specified for parameter 3
   ### The error may involve com.duoku.vipintegral.dao.vipscore.UserScoreLevelMapper.insertOrUpdate-Inline
   ### The error occurred while setting parameters
   ### SQL: INSERT INTO test_a (id,col_1,col_2) VALUES(1,?, ?) ON DUPLICATE KEY UPDATE col_2 = col_2 + ?
   ### Cause: java.sql.SQLException: No value specified for parameter 3
   ; bad SQL grammar []; nested exception is java.sql.SQLException: No value specified for parameter 3
   ```
   ### Reason analyze (If you can)
   Debug from the source,found that the num of parameters just only get from `InsertValuesSegment`, but the parameter after `ON DUPLICATE KEY UPDATE` is not included in the calculation.And I also can not find values that belong to 'OnDuplicateKey' expression  in `OnDuplicateKeyColumnsSegment`.
   
   https://github.com/apache/incubator-shardingsphere/blob/85f2ff877a7aaf122998964a0d03f7c9b2830e36/sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java#L70
   
   `currentParameters` do not contains the parameter for 'ON DUPLICATE KEY UPDATE',and `parameters` is full.
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   - sql
   ```
   CREATE TABLE `user` (
     `id` int(10) unsigned NOT NULL COMMENT '主键',
     `col_1` varchar(20) NOT NULL DEFAULT '' COMMENT 'val_1',
     `col_2` int(10) NOT NULL DEFAULT '0' COMMENT 'val_int_2',
     PRIMARY KEY (`id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
   
   INSERT INTO table_a (id,col_1,col_2) VALUES(1,#{bean.val1}, #{bean.val2}) ON DUPLICATE KEY UPDATE col_2 = col_2 + #{bean.val2}
   ```
   - in mybatis3
   - any shareding rule.
   ### Example codes for reproduce this issue (such as a github link).
   

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


With regards,
Apache Git Services