shardingsphere
shardingsphere copied to clipboard
Insert error when field name was a keyword
Insert error when field name was a keyword.
Which version of ShardingSphere did you use?
4.0.0-RC1
Which project did you use? Sharding-JDBC or Sharding-Proxy?
Sharding-JDBC
Expected behavior
insert success.
Actual behavior
[main] INFO ShardingSphere-SQL - Logic SQL: INSERT INTO `ts_order` (`id`, `desc`) VALUES ('1', 'abc')
[main] INFO ShardingSphere-SQL - SQLStatement: InsertStatement(super=DMLStatement(super=AbstractSQLStatement(type=DML, tables=Tables(tables=[Table(name=ts_order, alias=Optional.absent())]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[AndCondition(conditions=[Condition(column=Column(name=id, tableName=ts_order), operator=EQUAL, compareOperator=null, positionValueMap={0=1}, positionIndexMap={})])])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[TableToken(tableName=ts_order, quoteCharacter=BACK_QUOTE, schemaNameLength=0), SQLToken(startIndex=23)], parametersIndex=0, logicSQL=INSERT INTO `ts_order` (`id`, `desc`) VALUES ('1', 'abc')), deleteStatement=false, updateTableAlias={}, updateColumnValues={}, whereStartIndex=0, whereStopIndex=0, whereParameterStartIndex=0, whereParameterEndIndex=0), columnNames=[id, desc], values=[InsertValue(columnValues=[org.apache.shardingsphere.core.parse.old.parser.expression.SQLTextExpression@5a62b2a4, org.apache.shardingsphere.core.parse.old.parser.expression.SQLTextExpression@1051817b])])
[main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: INSERT INTO `ts_order_0001` (id, desc) VALUES ('1', 'abc')
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc) VALUES ('1', 'abc')' at line 1
Reason analyze (If you can)
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).
DESC is Reserved Words which cannot use to be a column name.
FYI: https://dev.mysql.com/doc/refman/8.0/en/keywords.html
But you use back quote to mark desc, that is correct.
Let us investigate it.
When I use select statement, the result is correct.
[main] INFO ShardingSphere-SQL - Logic SQL: select id, `desc` from ts_order
[main] INFO ShardingSphere-SQL - SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=ts_order, alias=Optional.absent())]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[TableToken(tableName=ts_order, quoteCharacter=NONE, schemaNameLength=0)], parametersIndex=0, logicSQL=select id, `desc` from ts_order)), containStar=false, firstSelectItemStartIndex=7, selectListStopIndex=16, groupByLastIndex=0, items=[CommonSelectItem(expression=id, alias=Optional.absent()), CommonSelectItem(expression=desc, alias=Optional.absent())], groupByItems=[], orderByItems=[], limit=null, subqueryStatement=null, subqueryStatements=[], subqueryConditions=[])
[main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: select id, `desc` from ts_order_0000
[main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: select id, `desc` from ts_order_0001
the insert column name was wrong, the correct column name is desc not "desc"
Hi, this bug has been fixed #2387, thanks again. @AlbertTao