shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Encryp-JDBC rewrite wrong sql when sql contain character '('

Open HongJinFeng opened this issue 7 years ago • 6 comments

Encrypt-JDBC rewrite wrong sql when sql contain character '('. Besides, it works normally with the version of 4.0.0-RC2.

Version of ShardingSphere 4.0.0-RC3

JDBC I use Encrypt-JDBC

Expected behavior Rewrite the sql correct which is contain character '('

Actual behavior The rewrite sql error when sql contain character '('

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

1.MySQL table and encrypt configuration table: create table t_demo{ username varchar(20), phone varchar(20), username_encrypt(64), phone_encrypt(64) } encrypt configuration spring.shardingsphere.datasource.name = ds spring.shardingsphere.datasource.ds.type = com.alibaba.druid.pool.DruidDataSource spring.shardingsphere.datasource.ds.driver-class-name = com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds.url = xxx spring.shardingsphere.datasource.ds.username = xxx spring.shardingsphere.datasource.ds.password = xxx spring.shardingsphere.encrypt.encryptors.encryptor_aes.type = AES spring.shardingsphere.encrypt.tables.t_demo.columns.username.plainColumn = username spring.shardingsphere.encrypt.tables.t_demo.columns.username.cipherColumn = username_encrypt spring.shardingsphere.encrypt.tables.t_demo.columns.phone.plainColumn = phone spring.shardingsphere.encrypt.tables.t_demo.columns.phone.cipherColumn = phone_encrypt spring.shardingsphere.encrypt.tables.t_demo.columns.phone.encryptor = encryptor_aes spring.shardingsphere.encrypt.tables.t_demo.columns.username.encryptor = encryptor_aes

2.My dao method definition List query(@Param("phoneList") List phoneList);

3.My mybatis sql

4.Encrypt-JDBC rewrite sql(The rewrite sql get more left parenthesis) method: EncryptPreparedStatement.getSQLUnit(final String sql)

sql: select * from t_demo t where (t.username_encrypt in (('xxx','xxxx') or t.phone_encrypt in (('xxx','xxxx')) and delete = 0;

HongJinFeng avatar Nov 28 '19 02:11 HongJinFeng

i hava two question for this issue,First,this spring.shardingsphere.encrypt.encryptors.encryptor_aes.props.aes.key.value = ? Second, SELECT * FROM t_demo t WHERE (t.username IN #{phone} OR t.phone IN #{phone} ) AND delete = 0 this sql is error,Is that Right, SELECT * FROM t_demo t WHERE (t.username IN ('13718687573') OR t.phone IN ('13718687573'))

zhaojinchao95 avatar Nov 29 '19 07:11 zhaojinchao95

Frist question: Copy from my project(I use spi to extend encryptor). It is not needed here.

Secondary questuon: I dont know with my content was formated to ' SELECT * FROM t_demo t WHERE (t.username IN #{phone} OR t.phone IN #{phone} ) AND delete = 0' Actual content is image

HongJinFeng avatar Nov 29 '19 07:11 HongJinFeng

ok, I verified this,let me see

zhaojinchao95 avatar Nov 29 '19 07:11 zhaojinchao95

@terrymanu Please assign me to solve @HongJinFeng @zjcnb question.

SteNicholas avatar Nov 29 '19 08:11 SteNicholas

image

//to fix the bug for my project, I change the source core tentatively, so it is a litter different. image

@zjcnb Here get one more left parenthesis. When get conjunction text of 'username in (?,?)', the content already has a left parenthesis, so the rewrite sql get one more left parenthesis.

HongJinFeng avatar Nov 30 '19 01:11 HongJinFeng

@SteNicholas Thank you, assigned

terrymanu avatar Dec 04 '19 10:12 terrymanu