-
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
INSERT ... ON DUPLICATE KEY UPDATE ,Reporting the following error #2271
Comments
This function is OK in 3.0.1. Is it not possible to go to 4.0.0-RC1? |
Mysql "ON DUPLICATE KEY UPDATE" statement is not inserted, there are updates, should not report primary key conflict? |
I feel that this 4.0.0-RC1 introduces a new bug, and these features are OK in version 3.0.1. I have used the smallest version of 4.0.0 in the project to keep the wrong version. . I feel that I will not continue to upgrade in the future. |
Actual SQL: rw0 ::: insert into t_order 4.0.0-RC1 seems to cut off the statement behind me, do you see if it is? |
org.apache.shardingsphere.core.BaseShardingEngine#rewriteAndConvert(final String sql, final List parameters, final SQLRouteResult sqlRouteResult) |
@xfyang1989 Thanks for your analysis, I will investigate the cause of the error. |
@codefairy08 I want to use the mysql syntax(INSERT ... ON DUPLICATE KEY UPDATE), is there any other way? |
Consult a question, if I configure the default-data-source, other tables that do not need to be sub-tables can be queried by the original sql? |
all tables are not sharding table, it will be exexuted with the original sql. |
Is there any other way to avoid this problem? Minimal change |
private void appendInsertValuesToken(final SQLBuilder sqlBuilder, final InsertValuesToken insertValuesToken, final int count, final InsertOptimizeResult insertOptimizeResult) {
for (InsertOptimizeResultUnit each : insertOptimizeResult.getUnits()) {
encryptInsertOptimizeResultUnit(insertOptimizeResult.getColumnNames(), each);
}
sqlBuilder.appendPlaceholder(new InsertValuesPlaceholder(sqlStatement.getTables().getSingleTableName(), insertOptimizeResult.getColumnNames(), insertOptimizeResult.getUnits()));
appendRest(sqlBuilder, count, originalSQL.length());
}
private void appendRest(final SQLBuilder sqlBuilder, final int count, final int startIndex) {
int stopPosition = sqlTokens.size() - 1 == count ? originalSQL.length() : sqlTokens.get(count + 1).getStartIndex();
sqlBuilder.appendLiterals(originalSQL.substring(startIndex, stopPosition));
} Oh,the length of the originalSQL is the startIndex !!! |
When will the official version of 4.0.0-RC2 be released? |
@xfyang1989 @zlanzip |
sql:
insert into t_order (id, avl_inventory,
type
,create_person, create_time, update_person, update_time, is_deleted, version )
VALUES
(76667, 100, 1, 'xx(189870)', '2019-4-25 18:25:20', 'xx(189870)','2019-4-25 18:25:20', 0,0 ) ,
(78143, 100, 1, 'xx(189870)', '2019-4-25 18:25:20',
'xx(189870)', '2019-4-25 18:25:20', 0,0 )
ON DUPLICATE KEY UPDATE avl_inventory = VALUES(avl_inventory),
type
= VALUES(type
),create_time = VALUES(create_time), create_person = VALUES(create_person),
update_time = VALUES(update_time), update_person = VALUES(update_person);
error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '78143' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1283)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:783)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
at org.apache.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:65)
at org.apache.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:61)
at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback.execute0(SQLExecuteCallback.java:69)
at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback.execute(SQLExecuteCallback.java:58)
The text was updated successfully, but these errors were encountered: