You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/11/30 04:08:06 UTC

[shardingsphere] branch master updated: fix rewrite of rendering selectItem when encrypt (#8380)

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

zhangliang 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 f5cf407  fix rewrite of rendering selectItem when encrypt (#8380)
f5cf407 is described below

commit f5cf40742ca9c7520fbe7fe7d17b4f70772e8034
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Mon Nov 30 12:07:36 2020 +0800

    fix rewrite of rendering selectItem when encrypt (#8380)
---
 .../impl/EncryptProjectionTokenGenerator.java      | 16 ++++++++-----
 .../EncryptSQLRewriterParameterizedTest.java       |  2 +-
 .../encrypt/select_for_query_with_cipher.xml       |  6 ++---
 .../encrypt/select_for_query_with_plain.xml        |  6 ++---
 .../MixSQLRewriterParameterizedTest.java           |  2 +-
 .../resources/mix/select_for_query_with_cipher.xml | 16 ++++++-------
 .../resources/mix/select_for_query_with_plain.xml  | 12 +++++-----
 .../statement/CommonSQLStatementContext.java       | 26 ++++++++++++++++++++++
 8 files changed, 59 insertions(+), 27 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
index 6a1b60c..ed82743 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
@@ -28,6 +28,10 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Col
 import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
+import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandlerFactory;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -76,7 +80,7 @@ public final class EncryptProjectionTokenGenerator extends BaseEncryptSQLTokenGe
             if (isToGeneratedSQLToken(each, selectStatementContext, tableName)) {
                 ShorthandProjection shorthandProjection = getShorthandProjection((ShorthandProjectionSegment) each, selectStatementContext.getProjectionsContext());
                 if (!shorthandProjection.getActualColumns().isEmpty()) {
-                    result.add(generateSQLToken((ShorthandProjectionSegment) each, shorthandProjection, tableName, encryptTable));
+                    result.add(generateSQLToken((ShorthandProjectionSegment) each, shorthandProjection, tableName, encryptTable, selectStatementContext.getDatabaseType()));
                 }
             }
         }
@@ -100,14 +104,16 @@ public final class EncryptProjectionTokenGenerator extends BaseEncryptSQLTokenGe
                 : new SubstitutableColumnNameToken(segment.getStartIndex(), segment.getStopIndex(), encryptColumnName);
     }
     
-    private SubstitutableColumnNameToken generateSQLToken(final ShorthandProjectionSegment segment, 
-                                                          final ShorthandProjection shorthandProjection, final String tableName, final EncryptTable encryptTable) {
+    private SubstitutableColumnNameToken generateSQLToken(final ShorthandProjectionSegment segment,
+                                                          final ShorthandProjection shorthandProjection, final String tableName, final EncryptTable encryptTable, final DatabaseType databaseType) {
+        QuoteCharacter quoteCharacter = DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(DatabaseMetaDataDialectHandler::getQuoteCharacter).orElse(QuoteCharacter.NONE);
         List<String> shorthandExtensionProjections = new LinkedList<>();
         for (ColumnProjection each : shorthandProjection.getActualColumns()) {
             if (encryptTable.getLogicColumns().contains(each.getName())) {
-                shorthandExtensionProjections.add(new ColumnProjection(each.getOwner(), getEncryptColumnName(tableName, each.getName()), each.getName()).getExpressionWithAlias());
+                shorthandExtensionProjections.add(new ColumnProjection(null == each.getOwner() ? null : quoteCharacter.wrap(each.getOwner()),
+                        quoteCharacter.wrap(getEncryptColumnName(tableName, each.getName())), each.getName()).getExpressionWithAlias());
             } else {
-                shorthandExtensionProjections.add(each.getExpression());
+                shorthandExtensionProjections.add(null == each.getOwner() ? quoteCharacter.wrap(each.getName()) : quoteCharacter.wrap(each.getOwner()) + "." + quoteCharacter.wrap(each.getName()));
             }
         }
         return new SubstitutableColumnNameToken(segment.getStartIndex(), segment.getStopIndex(), Joiner.on(", ").join(shorthandExtensionProjections));
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
index da154ff..88900fd 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
@@ -71,7 +71,7 @@ public final class EncryptSQLRewriterParameterizedTest extends AbstractSQLRewrit
     @Override
     protected Collection<SQLRewriteUnit> createSQLRewriteUnits() throws IOException {
         YamlRootRuleConfigurations ruleConfigurations = createRuleConfigurations();
-        String databaseType = null == getTestParameters().getDatabaseType() ? "SQL92" : getTestParameters().getDatabaseType();
+        String databaseType = null == getTestParameters().getDatabaseType() ? "MySQL" : getTestParameters().getDatabaseType();
         Collection<ShardingSphereRule> rules = ShardingSphereRulesBuilder.build(new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(
                 ruleConfigurations.getRules()), DatabaseTypeRegistry.getTrunkDatabaseType(databaseType), ruleConfigurations.getDataSources());
         SQLStatementParserEngine sqlStatementParserEngine = new SQLStatementParserEngine(databaseType);
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_cipher.xml b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_cipher.xml
index 12b3140..4d7a967 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_cipher.xml
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_cipher.xml
@@ -61,16 +61,16 @@
     
     <rewrite-assertion id="select_with_unqualified_shorthand">
         <input sql="SELECT * FROM t_account" />
-        <output sql="SELECT account_id, cipher_certificate_number AS certificate_number, cipher_password AS password, cipher_amount AS amount, status FROM t_account" />
+        <output sql="SELECT `account_id`, `cipher_certificate_number` AS certificate_number, `cipher_password` AS password, `cipher_amount` AS amount, `status` FROM t_account" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_qualified_shorthand">
         <input sql="SELECT a.* FROM t_account a" />
-        <output sql="SELECT a.account_id, a.cipher_certificate_number AS certificate_number, a.cipher_password AS password, a.cipher_amount AS amount, a.status FROM t_account a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_certificate_number` AS certificate_number, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status` FROM t_account a" />
     </rewrite-assertion>
 
     <rewrite-assertion id="select_with_mix_qualified_shorthand_and_other_projection">
         <input sql="SELECT a.*, account_id, 1+1 FROM t_account a" />
-        <output sql="SELECT a.account_id, a.cipher_certificate_number AS certificate_number, a.cipher_password AS password, a.cipher_amount AS amount, a.status, account_id, 1+1 FROM t_account a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_certificate_number` AS certificate_number, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status`, account_id, 1+1 FROM t_account a" />
     </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_plain.xml b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_plain.xml
index bf48755..7dfd6b7 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_plain.xml
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/resources/encrypt/select_for_query_with_plain.xml
@@ -29,16 +29,16 @@
     
     <rewrite-assertion id="select_with_unqualified_shorthand">
         <input sql="SELECT * FROM t_account_bak" />
-        <output sql="SELECT account_id, cipher_certificate_number AS certificate_number, plain_password AS password, plain_amount AS amount, status FROM t_account_bak" />
+        <output sql="SELECT `account_id`, `cipher_certificate_number` AS certificate_number, `plain_password` AS password, `plain_amount` AS amount, `status` FROM t_account_bak" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_qualified_shorthand">
         <input sql="SELECT a.* FROM t_account_bak a" />
-        <output sql="SELECT a.account_id, a.cipher_certificate_number AS certificate_number, a.plain_password AS password, a.plain_amount AS amount, a.status FROM t_account_bak a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_certificate_number` AS certificate_number, `a`.`plain_password` AS password, `a`.`plain_amount` AS amount, `a`.`status` FROM t_account_bak a" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_mix_qualified_shorthand_and_other_projection">
         <input sql="SELECT a.*, account_id, 1+1 FROM t_account_bak a" />
-        <output sql="SELECT a.account_id, a.cipher_certificate_number AS certificate_number, a.plain_password AS password, a.plain_amount AS amount, a.status, account_id, 1+1 FROM t_account_bak a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_certificate_number` AS certificate_number, `a`.`plain_password` AS password, `a`.`plain_amount` AS amount, `a`.`status`, account_id, 1+1 FROM t_account_bak a" />
     </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
index d676d11..a72a6ba 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
@@ -78,7 +78,7 @@ public final class MixSQLRewriterParameterizedTest extends AbstractSQLRewriterPa
     @Override
     protected Collection<SQLRewriteUnit> createSQLRewriteUnits() throws IOException {
         YamlRootRuleConfigurations ruleConfigurations = createRuleConfigurations();
-        String databaseType = null == getTestParameters().getDatabaseType() ? "SQL92" : getTestParameters().getDatabaseType();
+        String databaseType = null == getTestParameters().getDatabaseType() ? "MySQL" : getTestParameters().getDatabaseType();
         Collection<ShardingSphereRule> rules = ShardingSphereRulesBuilder.build(new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(
                 ruleConfigurations.getRules()), DatabaseTypeRegistry.getTrunkDatabaseType(databaseType), ruleConfigurations.getDataSources());
         SQLStatementParserEngine sqlStatementParserEngine = new SQLStatementParserEngine(databaseType);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_cipher.xml b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_cipher.xml
index 775d03a..7e9ac71 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_cipher.xml
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_cipher.xml
@@ -44,14 +44,14 @@
     
     <rewrite-assertion id="select_with_unqualified_shorthand">
         <input sql="SELECT * FROM t_account" />
-        <output sql="SELECT account_id, cipher_password AS password, cipher_amount AS amount, status FROM t_account_0" />
-        <output sql="SELECT account_id, cipher_password AS password, cipher_amount AS amount, status FROM t_account_1" />
+        <output sql="SELECT `account_id`, `cipher_password` AS password, `cipher_amount` AS amount, `status` FROM t_account_0" />
+        <output sql="SELECT `account_id`, `cipher_password` AS password, `cipher_amount` AS amount, `status` FROM t_account_1" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_qualified_shorthand">
         <input sql="SELECT a.* FROM t_account a" />
-        <output sql="SELECT a.account_id, a.cipher_password AS password, a.cipher_amount AS amount, a.status FROM t_account_0 a" />
-        <output sql="SELECT a.account_id, a.cipher_password AS password, a.cipher_amount AS amount, a.status FROM t_account_1 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status` FROM t_account_0 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status` FROM t_account_1 a" />
     </rewrite-assertion>
 
     <rewrite-assertion id="select_with_sharding_qualified_shorthand_join_table">
@@ -62,14 +62,14 @@
 
     <rewrite-assertion id="select_with_encrypt_qualified_shorthand_join_table">
         <input sql="SELECT a.* FROM t_account a, t_account_detail b where a.password = b.password" />
-        <output sql="SELECT a.account_id, a.cipher_password AS password, a.cipher_amount AS amount, a.status FROM t_account_0 a, t_account_detail_0 b where a.assisted_query_password = b.password" />
-        <output sql="SELECT a.account_id, a.cipher_password AS password, a.cipher_amount AS amount, a.status FROM t_account_1 a, t_account_detail_1 b where a.assisted_query_password = b.password" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status` FROM t_account_0 a, t_account_detail_0 b where a.assisted_query_password = b.password" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status` FROM t_account_1 a, t_account_detail_1 b where a.assisted_query_password = b.password" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_mix_qualified_shorthand_and_other_projection">
         <input sql="SELECT a.*, account_id, 1+1 FROM t_account a" />
-        <output sql="SELECT a.account_id, a.cipher_password AS password, a.cipher_amount AS amount, a.status, account_id, 1+1 FROM t_account_0 a" />
-        <output sql="SELECT a.account_id, a.cipher_password AS password, a.cipher_amount AS amount, a.status, account_id, 1+1 FROM t_account_1 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status`, account_id, 1+1 FROM t_account_0 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`cipher_password` AS password, `a`.`cipher_amount` AS amount, `a`.`status`, account_id, 1+1 FROM t_account_1 a" />
     </rewrite-assertion>
     
     <!-- FIXME -->
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_plain.xml b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_plain.xml
index fb6735e..1b0a6f3 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_plain.xml
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/resources/mix/select_for_query_with_plain.xml
@@ -29,20 +29,20 @@
 
     <rewrite-assertion id="select_with_unqualified_shorthand">
         <input sql="SELECT * FROM t_account_bak" />
-        <output sql="SELECT account_id, plain_password AS password, plain_amount AS amount, status FROM t_account_bak_0" />
-        <output sql="SELECT account_id, plain_password AS password, plain_amount AS amount, status FROM t_account_bak_1" />
+        <output sql="SELECT `account_id`, `plain_password` AS password, `plain_amount` AS amount, `status` FROM t_account_bak_0" />
+        <output sql="SELECT `account_id`, `plain_password` AS password, `plain_amount` AS amount, `status` FROM t_account_bak_1" />
     </rewrite-assertion>
     
     <rewrite-assertion id="select_with_qualified_shorthand">
         <input sql="SELECT a.* FROM t_account_bak a" />
-        <output sql="SELECT a.account_id, a.plain_password AS password, a.plain_amount AS amount, a.status FROM t_account_bak_0 a" />
-        <output sql="SELECT a.account_id, a.plain_password AS password, a.plain_amount AS amount, a.status FROM t_account_bak_1 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`plain_password` AS password, `a`.`plain_amount` AS amount, `a`.`status` FROM t_account_bak_0 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`plain_password` AS password, `a`.`plain_amount` AS amount, `a`.`status` FROM t_account_bak_1 a" />
     </rewrite-assertion>
 
     <rewrite-assertion id="select_with_mix_qualified_shorthand_and_other_projection">
         <input sql="SELECT a.*, account_id, 1+1 FROM t_account_bak a" />
-        <output sql="SELECT a.account_id, a.plain_password AS password, a.plain_amount AS amount, a.status, account_id, 1+1 FROM t_account_bak_0 a" />
-        <output sql="SELECT a.account_id, a.plain_password AS password, a.plain_amount AS amount, a.status, account_id, 1+1 FROM t_account_bak_1 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`plain_password` AS password, `a`.`plain_amount` AS amount, `a`.`status`, account_id, 1+1 FROM t_account_bak_0 a" />
+        <output sql="SELECT `a`.`account_id`, `a`.`plain_password` AS password, `a`.`plain_amount` AS amount, `a`.`status`, account_id, 1+1 FROM t_account_bak_1 a" />
     </rewrite-assertion>
     
     <!-- FIXME -->
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java
index 8882bfc..8d067fa 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/CommonSQLStatementContext.java
@@ -19,7 +19,14 @@ package org.apache.shardingsphere.infra.binder.statement;
 
 import lombok.Getter;
 import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.SQL92Statement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement;
 
 import java.util.Collections;
 
@@ -34,9 +41,28 @@ public class CommonSQLStatementContext<T extends SQLStatement> implements SQLSta
     private final T sqlStatement;
     
     private final TablesContext tablesContext;
+
+    private final DatabaseType databaseType;
     
     public CommonSQLStatementContext(final T sqlStatement) {
         this.sqlStatement = sqlStatement;
+        this.databaseType = initDatabaseType(sqlStatement);
         tablesContext = new TablesContext(Collections.emptyList());
     }
+
+    private DatabaseType initDatabaseType(final SQLStatement sqlStatement) {
+        DatabaseType databaseType = null;
+        if (sqlStatement instanceof MySQLStatement) {
+            databaseType = DatabaseTypeRegistry.getActualDatabaseType("MySQL");
+        } else if (sqlStatement instanceof PostgreSQLStatement) {
+            databaseType = DatabaseTypeRegistry.getActualDatabaseType("PostgreSQL");
+        } else if (sqlStatement instanceof OracleStatement) {
+            databaseType = DatabaseTypeRegistry.getActualDatabaseType("Oracle");
+        } else if (sqlStatement instanceof SQLServerStatement) {
+            databaseType = DatabaseTypeRegistry.getActualDatabaseType("SQLServer");
+        } else if (sqlStatement instanceof SQL92Statement) {
+            databaseType = DatabaseTypeRegistry.getActualDatabaseType("SQL92");
+        }
+        return databaseType;
+    }
 }