This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a9a490d289 Add prepared statement query for xml assertions (#34111)
3a9a490d289 is described below

commit 3a9a490d28979b5640c5f9d3178ed0d016368321
Author: ZhangCheng <chengzh...@apache.org>
AuthorDate: Fri Dec 20 18:22:10 2024 +0800

    Add prepared statement query for xml assertions (#34111)
---
 .../test/e2e/engine/type/dql/GeneralDQLE2EIT.java  | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git 
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java
 
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java
index 4d5dc311b09..3fb3f146b52 100644
--- 
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java
+++ 
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/dql/GeneralDQLE2EIT.java
@@ -69,6 +69,14 @@ class GeneralDQLE2EIT extends BaseDQLE2EIT {
                 || "proxy".equals(testParam.getAdapter()) && 
"empty_storage_units".equalsIgnoreCase(testParam.getScenario())) {
             return;
         }
+        if (SQLExecuteType.LITERAL == context.getSqlExecuteType()) {
+            assertQueryForStatementWithXmlExpected(context);
+        } else {
+            assertQueryForPreparedStatementWithXmlExpected(context);
+        }
+    }
+    
+    private void assertQueryForStatementWithXmlExpected(final E2ETestContext 
context) throws SQLException {
         try (
                 Connection connection = 
getEnvironmentEngine().getTargetDataSource().getConnection();
                 Statement statement = connection.createStatement();
@@ -77,6 +85,19 @@ class GeneralDQLE2EIT extends BaseDQLE2EIT {
         }
     }
     
+    private void assertQueryForPreparedStatementWithXmlExpected(final 
E2ETestContext context) throws SQLException {
+        try (
+                Connection connection = 
getEnvironmentEngine().getTargetDataSource().getConnection();
+                PreparedStatement preparedStatement = 
connection.prepareStatement(context.getSQL())) {
+            for (SQLValue each : context.getAssertion().getSQLValues()) {
+                preparedStatement.setObject(each.getIndex(), each.getValue());
+            }
+            try (ResultSet resultSet = preparedStatement.executeQuery()) {
+                assertResultSet(context, resultSet);
+            }
+        }
+    }
+    
     private void assertExecuteQueryWithExpectedDataSource(final 
AssertionTestParameter testParam, final E2ETestContext context) throws 
SQLException {
         try (
                 Connection actualConnection = 
getEnvironmentEngine().getTargetDataSource().getConnection();
@@ -143,6 +164,14 @@ class GeneralDQLE2EIT extends BaseDQLE2EIT {
         if ("jdbc".equals(testParam.getAdapter())) {
             return;
         }
+        if (SQLExecuteType.LITERAL == context.getSqlExecuteType()) {
+            assertExecuteForStatementWithXmlExpected(context);
+        } else {
+            assertExecuteForPreparedStatementWithXmlExpected(context);
+        }
+    }
+    
+    private void assertExecuteForStatementWithXmlExpected(final E2ETestContext 
context) throws SQLException {
         try (
                 Connection connection = 
getEnvironmentEngine().getTargetDataSource().getConnection();
                 Statement statement = connection.createStatement()) {
@@ -152,6 +181,20 @@ class GeneralDQLE2EIT extends BaseDQLE2EIT {
         }
     }
     
+    private void assertExecuteForPreparedStatementWithXmlExpected(final 
E2ETestContext context) throws SQLException {
+        try (
+                Connection connection = 
getEnvironmentEngine().getTargetDataSource().getConnection();
+                PreparedStatement preparedStatement = 
connection.prepareStatement(context.getSQL())) {
+            for (SQLValue each : context.getAssertion().getSQLValues()) {
+                preparedStatement.setObject(each.getIndex(), each.getValue());
+            }
+            assertTrue(preparedStatement.execute(), "Not a query 
preparedStatement.");
+            try (ResultSet resultSet = preparedStatement.getResultSet()) {
+                assertResultSet(context, resultSet);
+            }
+        }
+    }
+    
     private void assertExecuteWithExpectedDataSource(final 
AssertionTestParameter testParam, final E2ETestContext context) throws 
SQLException {
         try (
                 Connection actualConnection = 
getEnvironmentEngine().getTargetDataSource().getConnection();

Reply via email to