CodingBingo opened a new issue #12272:
URL: https://github.com/apache/shardingsphere/issues/12272


   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   Current master branch.
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC 
   
   ### Expected behavior
   when i user shardingSephere-jdbc, this sql will occur error.
   ```
   insert into social_count (image, video, feeds, 
organization,createTime,updateTime) values (  ?, ?, ?, ?, now(), now()) on 
duplicate key update image = image + ?,video = video + ?,feeds = feeds + 
?,updateTime = now()
   ```
   social_count is single table in single database.
   
   error:
   ```
   bad SQL grammar []; nested exception is java.sql.SQLException: No value 
specified for parameter 6
   ```
   
   ### Reason analyze (If you can)
   In code of 
**org.apache.shardingsphere.infra.binder.segment.insert.values.OnDuplicateUpdateContext**,
 we have a function
   ```
        private int calculateParameterCount(final Collection<ExpressionSegment> 
assignments) {
           int result = 0;
           for (ExpressionSegment each : assignments) {
               if (each instanceof ParameterMarkerExpressionSegment) {
                   result++;
               } 
           }
           return result;
       }
   ```
   when i step into this function, each of element in assignments is an 
instanceof **BinaryOperationExpression**, not 
**ParameterMarkerExpressionSegment**, so it will course `parameterCount` always 
be 0.
   
   ### Example codes for reproduce this issue (such as a github link).
   To fix this bug, i modified the code as below.
   ```
   private int calculateParameterCount(final Collection<ExpressionSegment> 
assignments) {
           int result = 0;
           for (ExpressionSegment each : assignments) {
               if (each instanceof ParameterMarkerExpressionSegment) {
                   result++;
               } else if (each instanceof BinaryOperationExpression) {
                   if (((BinaryOperationExpression) each).getRight() instanceof 
ParameterMarkerExpressionSegment) {
                       result++;
                   }
               }
           }
           return result;
       }
   ```
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to