diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java index c4c8b83df64c2..8835d4492c9d8 100644 --- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java +++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dml/AdditionalDMLE2EIT.java @@ -51,7 +51,7 @@ void assertExecuteUpdateWithAutoGeneratedKeys(final AssertionTestParameter testP if (null == testParam.getTestCaseContext()) { return; } - if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { + if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType()) || isOracleInsertStatement(testParam.getDatabaseType().getType(), testParam.getTestCaseContext().getTestCase().getSql())) { return; } SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); @@ -65,6 +65,11 @@ void assertExecuteUpdateWithAutoGeneratedKeys(final AssertionTestParameter testP assertDataSet(testParam, containerComposer, actualUpdateCount); } + // TODO support oracle insert statement return auto generated keys + private boolean isOracleInsertStatement(final String databaseType, final String sql) { + return "Oracle".equals(databaseType) && sql.toUpperCase().startsWith("INSERT"); + } + private boolean isPostgreSQLOrOpenGauss(final String databaseType) { return "PostgreSQL".equals(databaseType) || "openGauss".equals(databaseType); } @@ -72,7 +77,7 @@ private boolean isPostgreSQLOrOpenGauss(final String databaseType) { private int executeUpdateForStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - int result = statement.executeUpdate(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), Statement.RETURN_GENERATED_KEYS); + int result = statement.executeUpdate(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS); assertGeneratedKeys(testParam, containerComposer, statement.getGeneratedKeys()); return result; } @@ -112,7 +117,7 @@ void assertExecuteUpdateWithColumnIndexes(final AssertionTestParameter testParam private int executeUpdateForStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - return statement.executeUpdate(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), new int[]{1}); + return statement.executeUpdate(containerComposer.getSQL(), new int[]{1}); } } @@ -147,7 +152,7 @@ void assertExecuteUpdateWithColumnNames(final AssertionTestParameter testParam) private int executeUpdateForStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - return statement.executeUpdate(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray())); + return statement.executeUpdate(containerComposer.getSQL()); } } @@ -184,7 +189,7 @@ void assertExecuteWithoutAutoGeneratedKeys(final AssertionTestParameter testPara private int executeForStatementWithoutAutoGeneratedKeys(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), Statement.NO_GENERATED_KEYS), "Not a DML statement."); + assertFalse(statement.execute(containerComposer.getSQL(), Statement.NO_GENERATED_KEYS), "Not a DML statement."); return statement.getUpdateCount(); } } @@ -207,7 +212,7 @@ void assertExecuteWithAutoGeneratedKeys(final AssertionTestParameter testParam) if (null == testParam.getTestCaseContext()) { return; } - if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) { + if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType()) || isOracleInsertStatement(testParam.getDatabaseType().getType(), testParam.getTestCaseContext().getTestCase().getSql())) { return; } SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam); @@ -224,8 +229,7 @@ void assertExecuteWithAutoGeneratedKeys(final AssertionTestParameter testParam) private int executeForStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam, final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute( - String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), Statement.RETURN_GENERATED_KEYS), "Not a DML statement."); + assertFalse(statement.execute(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS), "Not a DML statement."); assertGeneratedKeys(testParam, containerComposer, statement.getGeneratedKeys()); return statement.getUpdateCount(); } @@ -265,7 +269,7 @@ void assertExecuteWithColumnIndexes(final AssertionTestParameter testParam) thro private int executeForStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), new int[]{1}), "Not a DML statement."); + assertFalse(statement.execute(containerComposer.getSQL(), new int[]{1}), "Not a DML statement."); return statement.getUpdateCount(); } } @@ -302,7 +306,7 @@ void assertExecuteWithColumnNames(final AssertionTestParameter testParam) throws private int executeForStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { - assertFalse(statement.execute(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), new String[]{"TODO"}), "Not a DML statement."); + assertFalse(statement.execute(containerComposer.getSQL(), new String[]{"TODO"}), "Not a DML statement."); return statement.getUpdateCount(); } }