Browse Source

允许select中使用「.」

myuan 2 years ago
parent
commit
5458931de2
2 changed files with 19 additions and 8 deletions
  1. 14 5
      run_test.py
  2. 5 3
      src/calc.y

+ 14 - 5
run_test.py

@@ -397,20 +397,25 @@ async def assert_sqls():
     )
 
     await assert_sql(
-        """SELECT Sname
+        """SELECT Student.Sname
             FROM Student
             WHERE Sno IN (
                 SELECT Sno
                 FROM SC 
-                WHERE Cno='81003'
-        );""",
+                WHERE SC.Cno='81003'
+            );
+        """,
         [
             {
                 "type": "select",
                 "select_cols": [
                     {
                         "type": "select_column",
-                        "target": {"type": "identifier", "value": "Sname"},
+                        "target": {
+                            "type": "table_field",
+                            "table": "Student",
+                            "field": "Sname",
+                        },
                     }
                 ],
                 "table_name": "Student",
@@ -428,7 +433,11 @@ async def assert_sqls():
                         "table_name": "SC",
                         "where": {
                             "type": "相等",
-                            "left": {"type": "identifier", "value": "Cno"},
+                            "left": {
+                                "type": "table_field",
+                                "table": "SC",
+                                "field": "Cno",
+                            },
                             "right": {"type": "string", "value": "'81003'"},
                         },
                     },

+ 5 - 3
src/calc.y

@@ -374,7 +374,9 @@ select_stmt: SELECT select_items FROM IDENTIFIER op_where_expr {
 		cJSON_AddStringToObject(node, "table_name", $4);
 		cJSON_AddItemToObject(node, "where", $5);
 		$$=node;
-};
+}
+;
+
 select_items: select_item {
 		cJSON* node = cJSON_CreateArray();
 		cJSON_AddItemToArray(node, $1);
@@ -385,13 +387,13 @@ select_items: select_item {
 		$$=$1;
 	}
 ;
-select_item: identifier_or_const_value {
+select_item: single_expr {
 		cJSON* node = cJSON_CreateObject();
 		cJSON_AddStringToObject(node, "type", "select_column");
 		cJSON_AddItemToObject(node, "target", $1);
 		$$=node;
 	}
-	| identifier_or_const_value AS IDENTIFIER {
+	| single_expr AS IDENTIFIER {
 		cJSON* node = cJSON_CreateObject();
 		cJSON_AddStringToObject(node, "type", "select_column");
 		cJSON_AddItemToObject(node, "target", $1);