tuohai666 commented on a change in pull request #4502: #4501, Identify MySQL 
syntax allowed in Prepared Statements
URL: 
https://github.com/apache/incubator-shardingsphere/pull/4502#discussion_r386960144
 
 

 ##########
 File path: 
sharding-proxy/sharding-proxy-frontend/sharding-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/shardingproxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
 ##########
 @@ -17,38 +17,79 @@
 
 package 
org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.binary.prepare;
 
-import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
 import 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
 import org.apache.shardingsphere.shardingproxy.frontend.api.CommandExecutor;
 import 
org.apache.shardingsphere.shardingproxy.transport.mysql.constant.MySQLColumnType;
+import 
org.apache.shardingsphere.shardingproxy.transport.mysql.constant.MySQLServerErrorCode;
 import 
org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command.query.MySQLColumnDefinition41Packet;
 import 
org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command.query.binary.MySQLBinaryStatementRegistry;
 import 
org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command.query.binary.prepare.MySQLComStmtPrepareOKPacket;
 import 
org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command.query.binary.prepare.MySQLComStmtPreparePacket;
 import 
org.apache.shardingsphere.shardingproxy.transport.mysql.packet.generic.MySQLEofPacket;
+import 
org.apache.shardingsphere.shardingproxy.transport.mysql.packet.generic.MySQLErrPacket;
 import org.apache.shardingsphere.shardingproxy.transport.packet.DatabasePacket;
+import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
 import org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement;
 
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.LinkedList;
+import java.util.Set;
 
 /**
  * COM_STMT_PREPARE command executor for MySQL.
+ *
+ * @see <a 
href="https://dev.mysql.com/doc/refman/5.7/en/sql-prepared-statements.html";>SQL 
Syntax Allowed in Prepared Statements</a>
  */
 public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
     
+    private static final Set<String> SQL_SYNTAX_ALLOWED = new HashSet<>();
+    
+    private static final int MAX_CHECK_TOKENS = "FLUSH TABLES WITH READ 
LOCK".split("\\W+").length;
+    
     private static final MySQLBinaryStatementRegistry 
PREPARED_STATEMENT_REGISTRY = MySQLBinaryStatementRegistry.getInstance();
     
     private final MySQLComStmtPreparePacket packet;
     
     private final LogicSchema logicSchema;
     
+    static {
+        SQL_SYNTAX_ALLOWED.addAll(Arrays.asList("ALTER" + "TABLE", "ALTER" + 
"USER", "ANALYZE" + "TABLE",
+            "CACHE" + "INDEX", "CALL", "CHANGE" + "MASTER", "CHECKSUM" + 
"TABLE", "CHECKSUM" + "TABLES",
+            "COMMIT", "CREATE" + "INDEX", "DROP" + "INDEX", "CREATE" + 
"DATABASE", "RENAME" + "DATABASE",
+            "DROP" + "DATABASE", "CREATE" + "TABLE", "DROP" + "TABLE", 
"CREATE" + "USER", "RENAME" + "USER",
+            "DROP" + "USER", "CREATE" + "VIEW", "DROP" + "VIEW", "DELETE", 
"DO", "FLUSH" + "TABLE",
+            "FLUSH" + "TABLES", "FLUSH" + "TABLES" + "WITH" + "READ" + "LOCK", 
"FLUSH" + "HOSTS",
+            "FLUSH" + "PRIVILEGES", "FLUSH" + "LOGS", "FLUSH" + "STATUS", 
"FLUSH" + "MASTER", "FLUSH" + "SLAVE",
+            "FLUSH" + "DES_KEY_FILE", "FLUSH" + "USER" + "RESOURCES", "GRANT", 
"INSERT", "INSTALL" + "PLUGIN",
+            "KILL", "LOAD" + "INDEX" + "INTO" + "CACHE", "OPTIMIZE" + "TABLE", 
"RENAME" + "TABLE",
+            "REPAIR" + "TABLE", "REPLACE", "RESET" + "MASTER", "RESET" + 
"SLAVE", "RESET" + "QUERY CACHE",
 
 Review comment:
   Finish.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to