diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResult.java b/sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResult.java index c772dfa1c9b41..4825b4d2c8fb3 100644 --- a/sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResult.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResult.java @@ -69,7 +69,7 @@ private Iterator init(final List queryResults memoryResultSetRow.setCell(1, logicTableName); String createTableDDL = memoryResultSetRow.getCell(2).toString(); SQLParsingEngine sqlParsingEngine = new SQLParsingEngine(DatabaseType.MySQL, createTableDDL, shardingRule); - String actualTableName = sqlParsingEngine.parse().getTables().getSingleTableName(); + String actualTableName = sqlParsingEngine.parse(true).getTables().getSingleTableName(); if (actualTableName.startsWith("`")) { logicTableName = "`" + logicTableName + "`"; } diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/parsing/SQLParsingEngine.java b/sharding-core/src/main/java/io/shardingjdbc/core/parsing/SQLParsingEngine.java index 4e3eb69aaeff0..e258fdd8ed0b8 100755 --- a/sharding-core/src/main/java/io/shardingjdbc/core/parsing/SQLParsingEngine.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/parsing/SQLParsingEngine.java @@ -17,6 +17,7 @@ package io.shardingjdbc.core.parsing; +import com.google.common.base.Optional; import io.shardingjdbc.core.constant.DatabaseType; import io.shardingjdbc.core.parsing.cache.ParsingResultCache; import io.shardingjdbc.core.parsing.lexer.LexerEngine; @@ -45,23 +46,28 @@ public final class SQLParsingEngine { /** * Parse SQL. * + * @param useCache use cache or not * @return parsed SQL statement */ - public SQLStatement parse() { - SQLStatement cachedSQLStatement = ParsingResultCache.getInstance().getSQLStatement(sql); - if (null != cachedSQLStatement) { - return cachedSQLStatement; + public SQLStatement parse(final boolean useCache) { + Optional cachedSQLStatement = getSQLStatementFromCache(useCache); + if (cachedSQLStatement.isPresent()) { + return cachedSQLStatement.get(); } LexerEngine lexerEngine = LexerEngineFactory.newInstance(dbType, sql); lexerEngine.nextToken(); SQLStatement result = SQLParserFactory.newInstance(dbType, lexerEngine.getCurrentToken().getType(), shardingRule, lexerEngine).parse(); // TODO cannot cache InsertStatement here by generate key, should not modify original InsertStatement on router. - if (!findGeneratedKeyToken(result)) { + if (useCache && !findGeneratedKeyToken(result)) { ParsingResultCache.getInstance().put(sql, result); } return result; } + private Optional getSQLStatementFromCache(final boolean useCache) { + return useCache ? Optional.fromNullable(ParsingResultCache.getInstance().getSQLStatement(sql)) : Optional.absent(); + } + private boolean findGeneratedKeyToken(final SQLStatement sqlStatement) { for (SQLToken each : sqlStatement.getSqlTokens()) { if (each instanceof GeneratedKeyToken) { diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/routing/PreparedStatementRoutingEngine.java b/sharding-core/src/main/java/io/shardingjdbc/core/routing/PreparedStatementRoutingEngine.java index 510f17859bd3b..0c06ef5791862 100644 --- a/sharding-core/src/main/java/io/shardingjdbc/core/routing/PreparedStatementRoutingEngine.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/routing/PreparedStatementRoutingEngine.java @@ -53,7 +53,7 @@ public PreparedStatementRoutingEngine(final String logicSQL, final ShardingRule */ public SQLRouteResult route(final List parameters) { if (null == sqlStatement) { - sqlStatement = sqlRouter.parse(logicSQL); + sqlStatement = sqlRouter.parse(logicSQL, true); } return sqlRouter.route(logicSQL, parameters, sqlStatement); } diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/routing/StatementRoutingEngine.java b/sharding-core/src/main/java/io/shardingjdbc/core/routing/StatementRoutingEngine.java index d1eb178c1b3bc..0cf3e18c75f7a 100644 --- a/sharding-core/src/main/java/io/shardingjdbc/core/routing/StatementRoutingEngine.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/routing/StatementRoutingEngine.java @@ -45,7 +45,7 @@ public StatementRoutingEngine(final ShardingRule shardingRule, final DatabaseTyp * @return route result */ public SQLRouteResult route(final String logicSQL) { - SQLStatement sqlStatement = sqlRouter.parse(logicSQL); + SQLStatement sqlStatement = sqlRouter.parse(logicSQL, false); return sqlRouter.route(logicSQL, Collections.emptyList(), sqlStatement); } } diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/DatabaseHintSQLRouter.java b/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/DatabaseHintSQLRouter.java index ce87e0c3b2b79..048997e419f51 100644 --- a/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/DatabaseHintSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/DatabaseHintSQLRouter.java @@ -44,7 +44,7 @@ public final class DatabaseHintSQLRouter implements SQLRouter { private final boolean showSQL; @Override - public SQLStatement parse(final String logicSQL) { + public SQLStatement parse(final String logicSQL, final boolean useCache) { return new SQLJudgeEngine(logicSQL).judge(); } diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/ParsingSQLRouter.java b/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/ParsingSQLRouter.java index f0b22a87edddb..e6cc11de147c4 100644 --- a/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/ParsingSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/ParsingSQLRouter.java @@ -69,9 +69,9 @@ public final class ParsingSQLRouter implements SQLRouter { private final List generatedKeys = new LinkedList<>(); @Override - public SQLStatement parse(final String logicSQL) { + public SQLStatement parse(final String logicSQL, final boolean useCache) { SQLParsingEngine parsingEngine = new SQLParsingEngine(databaseType, logicSQL, shardingRule); - SQLStatement result = parsingEngine.parse(); + SQLStatement result = parsingEngine.parse(useCache); if (result instanceof InsertStatement) { ((InsertStatement) result).appendGenerateKeyToken(shardingRule); } diff --git a/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/SQLRouter.java b/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/SQLRouter.java index 559833fb216eb..c75ae24eedff2 100644 --- a/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/SQLRouter.java +++ b/sharding-core/src/main/java/io/shardingjdbc/core/routing/router/SQLRouter.java @@ -33,9 +33,10 @@ public interface SQLRouter { * Parse SQL. * * @param logicSQL logic SQL + * @param useCache use cache to save SQL parse result or not * @return parse result */ - SQLStatement parse(String logicSQL); + SQLStatement parse(String logicSQL, boolean useCache); /** * Route SQL. diff --git a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateSupportedSQLParsingTest.java b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateSupportedSQLParsingTest.java index ba47aa322393c..94b424b6c4500 100644 --- a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateSupportedSQLParsingTest.java +++ b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateSupportedSQLParsingTest.java @@ -51,6 +51,6 @@ public static Collection getTestParameters() { @Test public void assertSupportedSQL() { String sql = sqlCasesLoader.getSupportedSQL(sqlCaseId, sqlCaseType, parserResultSetLoader.getParserResult(sqlCaseId).getParameters()); - new SQLStatementAssert(new SQLParsingEngine(databaseType, sql, getShardingRule()).parse(), sqlCaseId, sqlCaseType).assertSQLStatement(); + new SQLStatementAssert(new SQLParsingEngine(databaseType, sql, getShardingRule()).parse(false), sqlCaseId, sqlCaseType).assertSQLStatement(); } } diff --git a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateUnsupportedSQLParsingTest.java b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateUnsupportedSQLParsingTest.java index 5351c50b649f8..8650b1677f738 100644 --- a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateUnsupportedSQLParsingTest.java +++ b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/integrate/engine/IntegrateUnsupportedSQLParsingTest.java @@ -48,6 +48,6 @@ public static Collection getTestParameters() { @Test(expected = SQLParsingUnsupportedException.class) public void assertUnsupportedSQL() { - new SQLParsingEngine(databaseType, sqlCasesLoader.getUnsupportedSQL(sqlCaseId, sqlCaseType, Collections.emptyList()), getShardingRule()).parse(); + new SQLParsingEngine(databaseType, sqlCasesLoader.getUnsupportedSQL(sqlCaseId, sqlCaseType, Collections.emptyList()), getShardingRule()).parse(false); } } diff --git a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/DeleteStatementParserTest.java b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/DeleteStatementParserTest.java index 2100fcc72de5c..e041e9ae9a9cb 100644 --- a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/DeleteStatementParserTest.java +++ b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/DeleteStatementParserTest.java @@ -44,7 +44,7 @@ public final class DeleteStatementParserTest extends AbstractStatementParserTest public void parseWithoutCondition() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX", shardingRule); - DMLStatement deleteStatement = (DMLStatement) statementParser.parse(); + DMLStatement deleteStatement = (DMLStatement) statementParser.parse(false); assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); } @@ -53,7 +53,7 @@ public void parseWithoutParameter() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX xxx WHERE field4<10 AND TABLE_XXX.field1=1 AND field5>10 AND xxx.field2 IN (1,3) AND field6<=10 AND field3 BETWEEN 5 AND 20 AND field7>=10", shardingRule); - DMLStatement deleteStatement = (DMLStatement) statementParser.parse(); + DMLStatement deleteStatement = (DMLStatement) statementParser.parse(false); assertDeleteStatementWithoutParameter(deleteStatement); } @@ -81,7 +81,7 @@ public void parseWithParameter() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX xxx WHERE field4? AND field2 IN (?,?) AND field6<=? AND field3 BETWEEN ? AND ? AND field7>=?", shardingRule); - DMLStatement deleteStatement = (DMLStatement) statementParser.parse(); + DMLStatement deleteStatement = (DMLStatement) statementParser.parse(false); assertDeleteStatementWithParameter(deleteStatement); } @@ -107,13 +107,13 @@ private void assertDeleteStatementWithParameter(final DMLStatement deleteStateme @Test(expected = UnsupportedOperationException.class) public void parseStatementWithDeleteMultipleTable() { ShardingRule shardingRule = createShardingRule(); - new SQLParsingEngine(DatabaseType.MySQL, "DELETE TABLE_XXX1, TABLE_xxx2 FROM TABLE_XXX1 JOIN TABLE_XXX2", shardingRule).parse(); + new SQLParsingEngine(DatabaseType.MySQL, "DELETE TABLE_XXX1, TABLE_xxx2 FROM TABLE_XXX1 JOIN TABLE_XXX2", shardingRule).parse(false); } @Test(expected = UnsupportedOperationException.class) public void parseStatementWithDeleteMultipleTableWithUsing() { ShardingRule shardingRule = createShardingRule(); - new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX1, TABLE_xxx2 USING TABLE_XXX1 JOIN TABLE_XXX2", shardingRule).parse(); + new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX1, TABLE_xxx2 USING TABLE_XXX1 JOIN TABLE_XXX2", shardingRule).parse(false); } @Test @@ -125,7 +125,7 @@ public void parseWithSpecialSyntax() { private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) { ShardingRule shardingRule = createShardingRule(); - DMLStatement deleteStatement = (DMLStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse(); + DMLStatement deleteStatement = (DMLStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse(false); assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); assertFalse(deleteStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent()); Condition condition = deleteStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get(); diff --git a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/InsertStatementParserTest.java b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/InsertStatementParserTest.java index af5f4704be856..852903bac5c0b 100644 --- a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/InsertStatementParserTest.java +++ b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/InsertStatementParserTest.java @@ -52,7 +52,7 @@ public final class InsertStatementParserTest extends AbstractStatementParserTest public void assertParseWithoutParameter() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`, `field2`) VALUES (10, 1)", shardingRule); - InsertStatement insertStatement = (InsertStatement) statementParser.parse(); + InsertStatement insertStatement = (InsertStatement) statementParser.parse(false); assertInsertStatementWithoutParameter(insertStatement); } @@ -60,7 +60,7 @@ public void assertParseWithoutParameter() { public void assertParseWithParameter() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO TABLE_XXX (field1, field2) VALUES (?, ?)", shardingRule); - InsertStatement insertStatement = (InsertStatement) statementParser.parse(); + InsertStatement insertStatement = (InsertStatement) statementParser.parse(false); assertInsertStatementWithParameter(insertStatement); } @@ -68,7 +68,7 @@ public void assertParseWithParameter() { public void assertParseWithGenerateKeyColumnsWithoutParameter() { ShardingRule shardingRule = createShardingRuleWithGenerateKeyColumns(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`) VALUES (10)", shardingRule); - InsertStatement insertStatement = (InsertStatement) statementParser.parse(); + InsertStatement insertStatement = (InsertStatement) statementParser.parse(false); assertInsertStatementWithoutParameter(insertStatement); } @@ -84,7 +84,7 @@ private void assertInsertStatementWithoutParameter(final InsertStatement insertS public void assertParseWithGenerateKeyColumnsWithParameter() { ShardingRule shardingRule = createShardingRuleWithGenerateKeyColumns(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`) VALUES (?)", shardingRule); - InsertStatement insertStatement = (InsertStatement) statementParser.parse(); + InsertStatement insertStatement = (InsertStatement) statementParser.parse(false); assertInsertStatementWithParameter(insertStatement); } @@ -129,7 +129,7 @@ public void parseWithSpecialSyntax() { @SuppressWarnings("unchecked") private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) { ShardingRule shardingRule = createShardingRule(); - InsertStatement insertStatement = (InsertStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse(); + InsertStatement insertStatement = (InsertStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse(false); assertThat(insertStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); assertFalse(insertStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent()); Condition condition = insertStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get(); @@ -141,18 +141,18 @@ private void parseWithSpecialSyntax(final DatabaseType dbType, final String actu // TODO assert public void parseMultipleInsertForMySQL() { ShardingRule shardingRule = createShardingRule(); - new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO TABLE_XXX (`field1`, `field2`) VALUES (1, 'value_char'), (2, 'value_char')", shardingRule).parse(); + new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO TABLE_XXX (`field1`, `field2`) VALUES (1, 'value_char'), (2, 'value_char')", shardingRule).parse(false); } @Test(expected = SQLParsingUnsupportedException.class) public void parseInsertAllForOracle() { ShardingRule shardingRule = createShardingRule(); - new SQLParsingEngine(DatabaseType.Oracle, "INSERT ALL INTO TABLE_XXX (field1) VALUES (field1) SELECT field1 FROM TABLE_XXX2", shardingRule).parse(); + new SQLParsingEngine(DatabaseType.Oracle, "INSERT ALL INTO TABLE_XXX (field1) VALUES (field1) SELECT field1 FROM TABLE_XXX2", shardingRule).parse(false); } @Test(expected = SQLParsingUnsupportedException.class) public void parseInsertFirstForOracle() { ShardingRule shardingRule = createShardingRule(); - new SQLParsingEngine(DatabaseType.Oracle, "INSERT FIRST INTO TABLE_XXX (field1) VALUES (field1) SELECT field1 FROM TABLE_XXX2", shardingRule).parse(); + new SQLParsingEngine(DatabaseType.Oracle, "INSERT FIRST INTO TABLE_XXX (field1) VALUES (field1) SELECT field1 FROM TABLE_XXX2", shardingRule).parse(false); } } diff --git a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/UpdateStatementParserTest.java b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/UpdateStatementParserTest.java index 2ece1a7c85f78..a3675ad4bff5c 100644 --- a/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/UpdateStatementParserTest.java +++ b/sharding-core/src/test/java/io/shardingjdbc/core/parsing/parser/sql/UpdateStatementParserTest.java @@ -45,7 +45,7 @@ public final class UpdateStatementParserTest extends AbstractStatementParserTest public void parseWithoutCondition() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "UPDATE TABLE_XXX SET field1=field1+1", shardingRule); - DMLStatement updateStatement = (DMLStatement) statementParser.parse(); + DMLStatement updateStatement = (DMLStatement) statementParser.parse(false); assertThat(updateStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); } @@ -54,7 +54,7 @@ public void parseWithoutParameter() { ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "UPDATE TABLE_XXX xxx SET TABLE_XXX.field1=field1+1,xxx.field2=2 WHERE TABLE_XXX.field4<10 AND" + " TABLE_XXX.field1=1 AND xxx.field5>10 AND TABLE_XXX.field2 IN (1,3) AND xxx.field6<=10 AND TABLE_XXX.field3 BETWEEN 5 AND 20 AND xxx.field7>=10", shardingRule); - DMLStatement updateStatement = (DMLStatement) statementParser.parse(); + DMLStatement updateStatement = (DMLStatement) statementParser.parse(false); assertUpdateStatementWithoutParameter(updateStatement); } @@ -82,7 +82,7 @@ public void parseWithParameter() { String sql = "UPDATE TABLE_XXX AS xxx SET field1=field1+? WHERE field4? AND xxx.field2 IN (?, ?) AND field6<=? AND xxx.field3 BETWEEN ? AND ? AND field7>=?"; ShardingRule shardingRule = createShardingRule(); SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, sql, shardingRule); - DMLStatement updateStatement = (DMLStatement) statementParser.parse(); + DMLStatement updateStatement = (DMLStatement) statementParser.parse(false); assertUpdateStatementWitParameter(updateStatement); } @@ -109,7 +109,7 @@ private void assertUpdateStatementWitParameter(final DMLStatement updateStatemen @Test(expected = SQLParsingUnsupportedException.class) public void parseWithOr() { ShardingRule shardingRule = createShardingRule(); - new SQLParsingEngine(DatabaseType.Oracle, "UPDATE TABLE_XXX SET field1=1 WHERE field1<1 AND (field1 >2 OR field2 =1)", shardingRule).parse(); + new SQLParsingEngine(DatabaseType.Oracle, "UPDATE TABLE_XXX SET field1=1 WHERE field1<1 AND (field1 >2 OR field2 =1)", shardingRule).parse(false); } @Test @@ -123,7 +123,7 @@ public void parseWithSpecialSyntax() { private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) { ShardingRule shardingRule = createShardingRule(); - DMLStatement updateStatement = (DMLStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse(); + DMLStatement updateStatement = (DMLStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse(false); assertThat(updateStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); assertFalse(updateStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent()); Condition condition = updateStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get(); diff --git a/sharding-proxy/src/main/java/io/shardingjdbc/proxy/transport/mysql/packet/command/statement/prepare/ComStmtPreparePacket.java b/sharding-proxy/src/main/java/io/shardingjdbc/proxy/transport/mysql/packet/command/statement/prepare/ComStmtPreparePacket.java index 6a0f1b2b983d3..9f9d7b7ef8837 100644 --- a/sharding-proxy/src/main/java/io/shardingjdbc/proxy/transport/mysql/packet/command/statement/prepare/ComStmtPreparePacket.java +++ b/sharding-proxy/src/main/java/io/shardingjdbc/proxy/transport/mysql/packet/command/statement/prepare/ComStmtPreparePacket.java @@ -63,7 +63,7 @@ public List execute() { log.debug("COM_STMT_PREPARE received for Sharding-Proxy: {}", sql); List result = new LinkedList<>(); int currentSequenceId = 0; - SQLStatement sqlStatement = new SQLParsingEngine(DatabaseType.MySQL, sql, ShardingRuleRegistry.getInstance().getShardingRule()).parse(); + SQLStatement sqlStatement = new SQLParsingEngine(DatabaseType.MySQL, sql, ShardingRuleRegistry.getInstance().getShardingRule()).parse(true); result.add(new ComStmtPrepareOKPacket(++currentSequenceId, PreparedStatementRegistry.getInstance().register(sql), getNumColumns(sqlStatement), sqlStatement.getParametersIndex(), 0)); for (int i = 0; i < sqlStatement.getParametersIndex(); i++) { // TODO add column name