提交 433b7ecb authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Ignore constant default values of columns in gathering of generated keys

上级 96ab15f8
...@@ -339,7 +339,9 @@ public class Column { ...@@ -339,7 +339,9 @@ public class Column {
value = ValueNull.INSTANCE; value = ValueNull.INSTANCE;
} else { } else {
value = localDefaultExpression.getValue(session).convertTo(type); value = localDefaultExpression.getValue(session).convertTo(type);
if (!localDefaultExpression.isConstant()) {
session.getGeneratedKeys().add(this); session.getGeneratedKeys().add(this);
}
if (primaryKey) { if (primaryKey) {
session.setLastIdentity(value); session.setLastIdentity(value);
} }
...@@ -349,8 +351,10 @@ public class Column { ...@@ -349,8 +351,10 @@ public class Column {
if (value == ValueNull.INSTANCE) { if (value == ValueNull.INSTANCE) {
if (convertNullToDefault) { if (convertNullToDefault) {
value = localDefaultExpression.getValue(session).convertTo(type); value = localDefaultExpression.getValue(session).convertTo(type);
if (!localDefaultExpression.isConstant()) {
session.getGeneratedKeys().add(this); session.getGeneratedKeys().add(this);
} }
}
if (value == ValueNull.INSTANCE && !nullable) { if (value == ValueNull.INSTANCE && !nullable) {
if (mode.convertInsertNullToZero) { if (mode.convertInsertNullToZero) {
DataType dt = DataType.getDataType(type); DataType dt = DataType.getDataType(type);
......
...@@ -545,7 +545,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -545,7 +545,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testPrepareStatement_int_Execute(Connection conn) throws Exception { private void testPrepareStatement_int_Execute(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)",
Statement.NO_GENERATED_KEYS); Statement.NO_GENERATED_KEYS);
prep.execute(); prep.execute();
...@@ -579,7 +579,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -579,7 +579,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testPrepareStatement_int_ExecuteBatch(Connection conn) throws Exception { private void testPrepareStatement_int_ExecuteBatch(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)",
Statement.NO_GENERATED_KEYS); Statement.NO_GENERATED_KEYS);
prep.addBatch(); prep.addBatch();
...@@ -625,7 +625,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -625,7 +625,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testPrepareStatement_int_ExecuteLargeBatch(Connection conn) throws Exception { private void testPrepareStatement_int_ExecuteLargeBatch(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
JdbcPreparedStatement prep = (JdbcPreparedStatement) conn JdbcPreparedStatement prep = (JdbcPreparedStatement) conn
.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS); .prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS);
prep.addBatch(); prep.addBatch();
...@@ -673,7 +673,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -673,7 +673,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testPrepareStatement_int_ExecuteLargeUpdate(Connection conn) throws Exception { private void testPrepareStatement_int_ExecuteLargeUpdate(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
JdbcPreparedStatement prep = (JdbcPreparedStatement) conn JdbcPreparedStatement prep = (JdbcPreparedStatement) conn
.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS); .prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS);
prep.executeLargeUpdate(); prep.executeLargeUpdate();
...@@ -708,7 +708,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -708,7 +708,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testPrepareStatement_int_ExecuteUpdate(Connection conn) throws Exception { private void testPrepareStatement_int_ExecuteUpdate(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)", PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(VALUE) VALUES (10)",
Statement.NO_GENERATED_KEYS); Statement.NO_GENERATED_KEYS);
prep.executeUpdate(); prep.executeUpdate();
...@@ -1366,7 +1366,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -1366,7 +1366,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testStatementExecute_int(Connection conn) throws Exception { private void testStatementExecute_int(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
stat.execute("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS); stat.execute("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS);
ResultSet rs = stat.getGeneratedKeys(); ResultSet rs = stat.getGeneratedKeys();
assertFalse(rs.next()); assertFalse(rs.next());
...@@ -1508,7 +1508,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -1508,7 +1508,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testStatementExecuteLargeUpdate_int(Connection conn) throws Exception { private void testStatementExecuteLargeUpdate_int(Connection conn) throws Exception {
JdbcStatement stat = (JdbcStatement) conn.createStatement(); JdbcStatement stat = (JdbcStatement) conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS); stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS);
ResultSet rs = stat.getGeneratedKeys(); ResultSet rs = stat.getGeneratedKeys();
assertFalse(rs.next()); assertFalse(rs.next());
...@@ -1650,7 +1650,7 @@ public class TestGetGeneratedKeys extends TestBase { ...@@ -1650,7 +1650,7 @@ public class TestGetGeneratedKeys extends TestBase {
private void testStatementExecuteUpdate_int(Connection conn) throws Exception { private void testStatementExecuteUpdate_int(Connection conn) throws Exception {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT,"
+ "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)"); + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
stat.executeUpdate("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS); stat.executeUpdate("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS);
ResultSet rs = stat.getGeneratedKeys(); ResultSet rs = stat.getGeneratedKeys();
assertFalse(rs.next()); assertFalse(rs.next());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论