-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encrypt error when associated query with same column name. #3352
Comments
Hi @KomachiSion , I think this issue is same like #3194. The root cause of this issue is that we can't get tableName by columnIndex correctly. /**
* Get sharding encryptor.
*
* @param columnIndex column index
* @return sharding encryptor
* @throws SQLException SQL exception
*/
public Optional<ShardingEncryptor> getShardingEncryptor(final int columnIndex) throws SQLException {
final String actualColumn = resultSetMetaData.getColumnName(columnIndex);
if (null == sqlStatementContext) {
return Optional.absent();
}
final Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
for (String each : tableNames) {
Optional<ShardingEncryptor> result = findShardingEncryptorWithTable(actualColumn, each);
if (result.isPresent()) {
return result;
}
}
return Optional.absent();
} The complete code is here. You can see SS try to get encryptor with all tableNames in sqlStatementContext, so we can't get encryptor correctly by same column name. |
Yes, there are no owner table information. JDBC resultSetMetadata do not contain, so we may get the owner table from parsingEngine. |
Can we just replace |
Which step should we replace? If the we can get |
I have a crazy idea, maybe it's unfeasible. |
There are two questions for your idea.
|
|
Why we can not get the column's owner tableName from resultSetMetaData? |
It's sound good, I will check it. Thanks. |
I think you should debug it with oracle driver again. |
I try it with mysql driver. In mysql's ResultSetMetaData, we can find infomation for column's owner tableName(aliasTableName) and originalTableName. But I think this way is not standard and universal.
/** Method getTableName may return a empty String. In this way, if we parse the original sql to relate the aliasTableName and originalTableName, in same time, we can get the relation of tableName and column by DatabaseMetaData. Maybe we can resolve it. |
@big-mountain-z @sunbufu @KomachiSion |
Bug Report
Which version of ShardingSphere did you use?
4.0.0-RC3-SNAPSHOT
Which project did you use? Sharding-JDBC or Sharding-Proxy?
Sharding-JDBC
Expected behavior
associated query and decrypt successully.
Actual behavior
Reason analyze (If you can)
the join tables has same column name, the column in first table is encrypted and in second not encrypted, but encryptor will try to decrypt the second table's column.
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Example codes for reproduce this issue (such as a github link).
https://github.com/apache/incubator-shardingsphere-example
module orchestration-raw-jdbc-example
The text was updated successfully, but these errors were encountered: