Browse Source

添加delete

myuan 2 năm trước cách đây
mục cha
commit
77c2928bb2
2 tập tin đã thay đổi với 31 bổ sung0 xóa
  1. 21 0
      run_test.py
  2. 10 0
      src/calc.y

+ 21 - 0
run_test.py

@@ -195,6 +195,27 @@ async def assert_sqls():
             }
         ],
     )
+    await assert_sql(
+        "delete from tb1 where c1 = 1 and c2= 3;",
+        [
+            {
+                "type": "delete",
+                "table_name": "tb1",
+                "where": [
+                    {
+                        "type": "where_condition",
+                        "left": {"type": "identifier", "value": "c1"},
+                        "right": {"type": "int", "value": 1},
+                    },
+                    {
+                        "type": "where_condition",
+                        "left": {"type": "identifier", "value": "c2"},
+                        "right": {"type": "int", "value": 3},
+                    },
+                ],
+            }
+        ],
+    )
 
 
 async def on_modified(event):

+ 10 - 0
src/calc.y

@@ -47,6 +47,7 @@ cJSON* jroot;
 %type <jv> insert_stmt insert_list 
 %type <jv> update_stmt update_list single_assign_item
 %type <jv> where_condition_item where_conditions identifier identifier_or_const_value
+%type <jv> delete_stmt
 
 %start statement
 
@@ -60,6 +61,7 @@ statement: NEWLINE
 sql_statement: create_table_stmt
 	| insert_stmt
 	| update_stmt
+	| delete_stmt
 ;
 
 create_table_stmt: CREATE TABLE IDENTIFIER NEWLINE
@@ -231,6 +233,14 @@ bin_compare_op: '=' {$$ = "=";}
 	| "!=" {$$ = "!=";}
 ;
 
+delete_stmt: DELETE FROM IDENTIFIER WHERE where_conditions NEWLINE {
+		cJSON* node = cJSON_CreateObject();
+		cJSON_AddStringToObject(node, "type", "delete");
+		cJSON_AddStringToObject(node, "table_name", $3);
+		cJSON_AddItemToObject(node, "where", $5);
+		cJSON_AddItemToArray(jroot, node);
+		$$=node;
+};
 %%
 
 int main(int ac, char** av) {