huangguojun00 opened a new issue #7547:
URL: https://github.com/apache/shardingsphere/issues/7547


   I want to konw why (a.bill_code = 1 or 1=1) can route to table but without 
parentheses can not.
   
   This is my sql:
   `select * from table_1 a where ( a.bill_code = #{billCode} or 1=1 ) and 
a.gmt_modified BETWEEN #{start} and #{end}";
   `
   
   my target: I want to select data using date; but 'billcode' is the keyword 
of sharding db and table,  at first i try to use the above sql without 
parentheses in order to let sharding-jdbc can route. but it dosn't work.  and 
then i add parentheses . it worked.
   
   this is sql log without parentheses :
   2020-09-22 10:03:33.436 [main] INFO  ShardingSphere-SQL - Actual SQL: ds1 
::: select * from table_1 a where  a.bill_code = ? or 1=1 and a.gmt_modified 
BETWEEN ? and ? ::: [2, 2020-09-10 11:10:00.0, 2020-09-22 10:03:32.979]
   2020-09-22 10:03:33.436 [main] INFO  ShardingSphere-SQL - Actual SQL: ds1 
::: select * from table_2 a where  a.bill_code = ? or 1=1 and a.gmt_modified 
BETWEEN ? and ? ::: [2, 2020-09-10 11:10:00.0, 2020-09-22 10:03:32.979]
   2020-09-22 10:03:33.436 [main] INFO  ShardingSphere-SQL - Actual SQL: ds2 
::: select * from table_1 a where  a.bill_code = ? or 1=1 and a.gmt_modified 
BETWEEN ? and ? ::: [2, 2020-09-10 11:10:00.0, 2020-09-22 10:03:32.979]
   2020-09-22 10:03:33.436 [main] INFO  ShardingSphere-SQL - Actual SQL: ds2 
::: select * from table_2 a where  a.bill_code = ? or 1=1 and a.gmt_modified 
BETWEEN ? and ? ::: [2, 2020-09-10 11:10:00.0, 2020-09-22 10:03:32.979]
   
   this is sql log with parentheses:
   2020-09-22 10:10:03.753 [main] INFO  ShardingSphere-SQL - Actual SQL: ds1 
::: select * from table_1 a where ( a.bill_code = ? or 1=1 ) and a.gmt_modified 
BETWEEN ? and ? ::: [2, 2020-09-10 11:10:00.0, 2020-09-22 10:10:03.277]
   


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


Reply via email to