Browse Source

添加drop测试

myuan 2 years ago
parent
commit
081c87ce02
3 changed files with 19 additions and 3 deletions
  1. 1 0
      src/parser.l
  2. 12 3
      src/parser.y
  3. 6 0
      tests_config.py

+ 1 - 0
src/parser.l

@@ -36,6 +36,7 @@ extern YYSTYPE yylval;
 "SET"		{return SET;}
 "JOIN"      {return JOIN;}
 "TABLE"		{return TABLE;}
+"DROP"		{return DROP;}
 
 "INT"       {cp_yylval_and_return(INT_T);}
 "FLOAT"     {cp_yylval_and_return(FLOAT_T);}

+ 12 - 3
src/parser.y

@@ -59,7 +59,7 @@ cJSON* jroot;
 
 %token IDENTIFIER 
 
-%token SELECT FROM WHERE INSERT INTO VALUES DELETE UPDATE SET JOIN CREATE TABLE 
+%token SELECT FROM WHERE INSERT INTO VALUES DELETE UPDATE SET JOIN CREATE TABLE DROP
 %token AS ON
 %token AND OR NOT IN
 %token INT_V FLOAT_V STRING_V // 作为 value 出现的
@@ -78,9 +78,9 @@ cJSON* jroot;
 %type <jv> insert_stmt insert_list 
 %type <jv> update_stmt update_list single_assign_item
 %type <jv> where_condition_item identifier identifier_or_const_value 
-%type <jv> delete_stmt select_stmt select_item select_items 
+%type <jv> delete_stmt select_stmt select_item select_items drop_stmt
 %type <jv> data_value_list identifier_or_const_value_or_const_value_list
-%type <jv> search_expr compare_expr single_expr expr where_expr logical_expr negative_expr op_where_expr expr_list contains_expr
+%type <jv> compare_expr single_expr where_expr logical_expr negative_expr op_where_expr expr_list contains_expr
 %type <jv> op_join table_field column_name
 
 
@@ -109,6 +109,7 @@ sql_statement: create_table_stmt NEWLINE {cJSON_AddItemToArray(jroot, $1);}
 	| update_stmt NEWLINE {cJSON_AddItemToArray(jroot, $1);}
 	| delete_stmt NEWLINE {cJSON_AddItemToArray(jroot, $1);}
 	| select_stmt NEWLINE {cJSON_AddItemToArray(jroot, $1);}
+	| drop_stmt   NEWLINE {cJSON_AddItemToArray(jroot, $1);}
 ;
 
 create_table_stmt: CREATE TABLE IDENTIFIER
@@ -424,6 +425,14 @@ select_item: single_expr {
 	}
 ;
 
+drop_stmt: DROP TABLE IDENTIFIER {
+		cJSON* node = cJSON_CreateObject();
+		cJSON_AddStringToObject(node, "type", "drop_table");
+		cJSON_AddStringToObject(node, "table_name", $3);
+		$$=node;
+	}
+;
+
 %%
 
 int main(int ac, char** av) {

+ 6 - 0
tests_config.py

@@ -485,4 +485,10 @@ sql_parser_tests = [
             }
         ],
     ),
+    ('drop table t1;', [{"type": "drop_table", "table_name": "t1"}]),
 ]
+
+sql_checker_tests = [
+    ('select * from t1 where t1.c1 = t2.c2;', True),
+    
+]