Skip to content

Commit af2df34

Browse files
committed
BREAKING! Split EXECUTE and EXECUTE IMMEDIATE to separate _stmt types
1 parent 588c152 commit af2df34

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/cst/PreparedStatements.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import { Alias } from "./Alias";
22
import { BaseNode, Keyword } from "./Base";
3-
import { Expr, Identifier, ListExpr } from "./Expr";
3+
import { EntityName, Expr, Identifier, ListExpr } from "./Expr";
44

55
export type AllPreparedStatementNodes =
66
| AllPreparedStatements
77
| ExecuteIntoClause
88
| ExecuteUsingClause;
99

10-
export type AllPreparedStatements = ExecuteStmt;
10+
export type AllPreparedStatements = ExecuteStmt | ExecuteImmediateStmt;
1111

1212
// EXECUTE
1313
export interface ExecuteStmt extends BaseNode {
1414
type: "execute_stmt";
1515
executeKw: Keyword<"EXECUTE">;
16-
immediateKw?: Keyword<"IMMEDIATE">;
16+
name: EntityName;
17+
}
18+
19+
export interface ExecuteImmediateStmt extends BaseNode {
20+
type: "execute_immediate_stmt";
21+
executeKw: Keyword<"EXECUTE">;
22+
immediateKw: Keyword<"IMMEDIATE">;
1723
expr: Expr;
1824
into?: ExecuteIntoClause;
1925
using?: ExecuteUsingClause;

src/parser.pegjs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ statement_mysql
9393

9494
statement_bigquery
9595
= proc_statement
96-
/ execute_stmt
96+
/ execute_immediate_stmt
9797
/ bigquery_statement
9898

9999
statement_postgres
@@ -5524,11 +5524,20 @@ raise_message
55245524
* ------------------------------------------------------------------------------------ *
55255525
*/
55265526
execute_stmt
5527-
= kw:(EXECUTE __) immedKw:(immediate_kw __)? expr:expr
5527+
= kw:(EXECUTE __) name:entity_name {
5528+
return loc({
5529+
type: "execute_stmt",
5530+
executeKw: read(kw),
5531+
name,
5532+
});
5533+
}
5534+
5535+
execute_immediate_stmt
5536+
= kw:(EXECUTE __) immedKw:(IMMEDIATE __) expr:expr
55285537
into:(__ execute_into_clause)?
55295538
using:(__ execute_using_clause)? {
55305539
return loc({
5531-
type: "execute_stmt",
5540+
type: "execute_immediate_stmt",
55325541
executeKw: read(kw),
55335542
immediateKw: read(immedKw),
55345543
expr,
@@ -5537,9 +5546,6 @@ execute_stmt
55375546
});
55385547
}
55395548

5540-
immediate_kw
5541-
= x:IMMEDIATE &bigquery { return x; }
5542-
55435549
execute_into_clause
55445550
= kw:(INTO __) variables:list$ident {
55455551
return loc({

src/showNode/prepared_statements.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export const preparedStatementsMap: FullTransformMap<
66
string,
77
AllPreparedStatementNodes
88
> = {
9-
execute_stmt: (node) =>
9+
execute_stmt: (node) => show([node.executeKw, node.name]),
10+
execute_immediate_stmt: (node) =>
1011
show([node.executeKw, node.immediateKw, node.expr, node.into, node.using]),
1112
execute_into_clause: (node) => show([node.intoKw, node.variables]),
1213
execute_using_clause: (node) => show([node.usingKw, node.values]),

0 commit comments

Comments
 (0)