Skip to content
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

Table name capitalization cannot be queried #529

Closed
hwck opened this issue Jan 2, 2018 · 3 comments
Closed

Table name capitalization cannot be queried #529

hwck opened this issue Jan 2, 2018 · 3 comments

Comments

@hwck
Copy link

hwck commented Jan 2, 2018

多张表分库,表名大写找不到表,只有其中一张表能查询,其他不能查询。
spring boot 1.5.9 mybatis3.4.5 shardingjdbc 2.0.1
其中一张表能查到数据,其他的表都报找不到表。表名都是大写 t1表无法查询,报错
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: io.shardingjdbc.core.exception.ShardingJdbcException: io.shardingjdbc.core.exception.ShardingJdbcException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xx.T1' doesn't exist

The error may exist in file [T1Mapper.xml]

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT * from T1

Cause: io.shardingjdbc.core.exception.ShardingJdbcException: io.shardingjdbc.core.exception.ShardingJdbcException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xx.T1' doesn't exist

T2表查询没有问题

private Map<String, DataSource> createDataSourceMap() {
HashMap<String, DataSource> dataSourceMap = new HashMap<>();
for (Map<String, String> database : myProps.getDatabase()) {
HikariDataSource ds = (HikariDataSource) DataSourceBuilder.create()
.url(database.get("url"))
.username(database.get("username"))
.password(database.get("password"))
.driverClassName(database.get("driveClassName"))
.type(HikariDataSource.class).build();
ds.setConnectionTestQuery("SELECT 1");
dataSourceMap.put(database.get("name"), ds);
}
return dataSourceMap;
}

@Bean
@Primary
public DataSource shardingDataSource() throws SQLException {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.getTableRuleConfigs().add(getT1TableRuleConfiguration());
    shardingRuleConfig.getTableRuleConfigs().add(getT2TableRuleConfiguration());
    shardingRuleConfig.getBindingTableGroups().add("T1, T2");
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("T1", PreciseModuloDatabaseShardingAlgorithm.class.getName()));
    return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new HashMap<String, Object>(), new Properties());
}

private TableRuleConfiguration getT1TableRuleConfiguration() {
    TableRuleConfiguration retailOrderTableRuleConfig = new TableRuleConfiguration();
    retailOrderTableRuleConfig.setLogicTable("T1");
    return retailOrderTableRuleConfig;
}

private TableRuleConfiguration getT2TableRuleConfiguration() {
TableRuleConfiguration retailOrderTableRuleConfig = new TableRuleConfiguration();
retailOrderTableRuleConfig.setLogicTable("T2");
return retailOrderTableRuleConfig;
}

@hwck
Copy link
Author

hwck commented Jan 3, 2018

当我配置 retailOrderTableRuleConfig.setLogicTable("T22");的时候,居然查询到数据,但是数据库确实没有这张表

@haocao haocao self-assigned this Jan 3, 2018
@hwck
Copy link
Author

hwck commented Jan 3, 2018

发现问题了
String tableName =
SQLUtil.getOriginalValue(sqlStatement.getTables().getTableNames().contains(tableToken.getTableName()) ? tableToken.getTableName() : tableToken.getOriginalLiterals(), databaseType);
麻烦帮忙尽快解决下,然后发版。谢谢啦

@haocao
Copy link
Member

haocao commented Jan 3, 2018

我们会在2.0.2版本中修复这个问题。

haocao added a commit that referenced this issue Jan 9, 2018
haocao added a commit that referenced this issue Jan 9, 2018
@haocao haocao closed this as completed Jan 11, 2018
@terrymanu terrymanu changed the title 表名大写无法查询 Table name capitalization cannot be queried Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants