apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.79k stars 6.7k forks source link

Fail to reset ResultSet cursor. can not get primary key value #26685

Closed yvkm closed 2 months ago

yvkm commented 1 year ago

Bug Report

When I insert a SQL statement without primary key, an SQL syntax error occurs.

DDL : CREATE TABLEconfig( config_idint(11) NOT NULL AUTO_INCREMENT , typetinyint(2) NULL DEFAULT NULL , datevarchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL , valuevarchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL , create_timedatetime NULL DEFAULT NULL, update_timedatetime NULL DEFAULT NULL, creatorvarchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, updatorvarchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, PRIMARY KEY (config_id) USING BTREE, INDEXdate(date) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 832 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;

log:

INFO Actual SQL: master ::: INSERT INTO config (type, date, value, create_time, update_time, creator, updator) VALUES (?, ?, ?, ?, ?, ?, ?) ::: [0, 2023-06-27, 100, 2023-06-27 18:34:22.752, 2023-06-27 18:34:22.765, axi, axi] ShardingSphere-SQL.log(SQLLogger.java:74)

INFO load KeywordChecker[mysql] extension by class[io.seata.rm.datasource.undo.mysql.keyword.MySQLKeywordChecker] i.s.c.l.EnhancedServiceLoader.loadFile(EnhancedServiceLoader.java:247)

INFO load TableMetaCache[mysql] extension by class[io.seata.rm.datasource.sql.struct.cache.MysqlTableMetaCache] i.s.c.l.EnhancedServiceLoader.loadFile(EnhancedServiceLoader.java:247)

INFO Logic SQL: SELECT * FROM config LIMIT 1 ShardingSphere-SQL.log(SQLLogger.java:74)

NFO SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional[org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment@5721aed5], lock=Optional.empty, window=Optional.empty) ShardingSphere-SQL.log(SQLLogger.java:74)

INFO Actual SQL: master ::: SELECT * FROM config LIMIT 1 ShardingSphere-SQL.log(SQLLogger.java:74)

WARN Fail to reset ResultSet cursor. can not get primary key value i.s.r.d.e.InsertExecutor.defaultByAuto(InsertExecutor.java:317)

ERROR org.springframework.jdbc.UncategorizedSQLException:

Error flushing statements. Cause: java.sql.SQLException: org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have an error in your SQL syntax

Cause: java.sql.SQLException: org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have an error in your SQL syntax

; uncategorized SQLException; SQL state [null]; error code [0]; org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have an error in your SQL syntax; nested exception is java.sql.SQLException: org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have an error in your SQL syntax

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)

at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.executeBatch(ServiceImpl.java:232)

at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.executeBatch(ServiceImpl.java:252)

at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:127)

at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl$$FastClassBySpringCGLIB$$76535273.invoke()

at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)

at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)

Which version of ShardingSphere did you use?

org.apache.shardingsphere shardingsphere-jdbc-core-spring-boot-starter 5.1.2

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

ShardingSphere-JDBC

Expected behavior

insert the SQL without primary key should work, because primary key is auto-increament.

Actual behavior

no primary key lead to fail.

Reason analyze (If you can)

After I insert this SQL with primary key, It works fine.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

terrymanu commented 2 months ago

shardingsphere-jdbc-core-spring-boot-starter is deprecated and removed in 5.3.0, please try new version and use ShardingSphere Driver.