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

If there is quoteCharacter for index name, sql can not be executed #2312

Closed
tristaZero opened this issue May 1, 2019 · 1 comment · Fixed by #2320 or #2323
Closed

If there is quoteCharacter for index name, sql can not be executed #2312

tristaZero opened this issue May 1, 2019 · 1 comment · Fixed by #2320 or #2323

Comments

@tristaZero
Copy link
Contributor

tristaZero commented May 1, 2019

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

4.0.0-RC1

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-Proxy

Expected behavior

The following SQL can be executed correctly.

CREATE TABLE `t_order` (   `order_id` varchar(100) NOT NULL,   `user_id` varchar(100) DEFAULT NULL,   `status` varchar(45) DEFAULT NULL,   PRIMARY KEY (`order_id`),   KEY `order_index_t_order` (`order_id`) )  DEFAULT CHARSET=utf8;

Actual behavior

An exception is thrown.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_t_order_0 (`order_id`) )  DEFAULT CHARSET=utf8' at line 1

Reason analyze (If you can)

The rewritten SQL is not correct:

CREATE TABLE t_order_0 ( order_id varchar(100) NOT NULL, user_id varchar(100) DEFAULT NULL, status varchar(45) DEFAULT NULL, PRIMARY KEY (order_id), KEY `order_index_t_order`_t_order_0 (`order_id`) ) DEFAULT CHARSET=utf8

The related code is:
In SQLRewriteEngine class:

private void appendIndexPlaceholder(final SQLBuilder sqlBuilder, final IndexToken indexToken, final int count) {
        String indexName = originalSQL.substring(indexToken.getStartIndex(), indexToken.getStopIndex() + 1);
        String logicTableName = indexToken.getTableName().toLowerCase();
        if (Strings.isNullOrEmpty(logicTableName)) {
            logicTableName = shardingRule.getLogicTableName(indexName);
        }
        sqlBuilder.appendPlaceholder(new IndexPlaceholder(indexName, logicTableName));
        appendRest(sqlBuilder, count, indexToken.getStopIndex() + 1);
    }

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).

@weiyuc
Copy link

weiyuc commented May 5, 2019

我现在也遇到这个问题了,请问一下什么时候能够修复?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants