File tree 3 files changed +14
-33
lines changed 3 files changed +14
-33
lines changed Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ pub enum SQLStatement {
179
179
/// DELETE
180
180
SQLDelete {
181
181
/// FROM
182
- relation : Option < Box < ASTNode > > ,
182
+ table_name : SQLObjectName ,
183
183
/// WHERE
184
184
selection : Option < Box < ASTNode > > ,
185
185
} ,
@@ -279,13 +279,10 @@ impl ToString for SQLStatement {
279
279
s
280
280
}
281
281
SQLStatement :: SQLDelete {
282
- relation ,
282
+ table_name ,
283
283
selection,
284
284
} => {
285
- let mut s = String :: from ( "DELETE" ) ;
286
- if let Some ( relation) = relation {
287
- s += & format ! ( " FROM {}" , relation. as_ref( ) . to_string( ) ) ;
288
- }
285
+ let mut s = format ! ( "DELETE FROM {}" , table_name. to_string( ) ) ;
289
286
if let Some ( selection) = selection {
290
287
s += & format ! ( " WHERE {}" , selection. as_ref( ) . to_string( ) ) ;
291
288
}
Original file line number Diff line number Diff line change @@ -1105,20 +1105,16 @@ impl Parser {
1105
1105
}
1106
1106
1107
1107
pub fn parse_delete ( & mut self ) -> Result < SQLStatement , ParserError > {
1108
- let relation: Option < Box < ASTNode > > = if self . parse_keyword ( "FROM" ) {
1109
- Some ( Box :: new ( self . parse_subexpr ( 0 ) ?) ) /* TBD (4) */
1110
- } else {
1111
- None
1112
- } ;
1113
-
1108
+ self . expect_keyword ( "FROM" ) ?;
1109
+ let table_name = self . parse_object_name ( ) ?;
1114
1110
let selection = if self . parse_keyword ( "WHERE" ) {
1115
1111
Some ( Box :: new ( self . parse_expr ( ) ?) )
1116
1112
} else {
1117
1113
None
1118
1114
} ;
1119
1115
1120
1116
Ok ( SQLStatement :: SQLDelete {
1121
- relation ,
1117
+ table_name ,
1122
1118
selection,
1123
1119
} )
1124
1120
}
Original file line number Diff line number Diff line change @@ -8,16 +8,10 @@ use sqlparser::sqltokenizer::*;
8
8
9
9
#[ test]
10
10
fn parse_delete_statement ( ) {
11
- let sql: & str = "DELETE FROM 'table'" ;
12
-
13
- match verified_stmt ( & sql) {
14
- SQLStatement :: SQLDelete { relation, .. } => {
15
- assert_eq ! (
16
- Some ( Box :: new( ASTNode :: SQLValue ( Value :: SingleQuotedString (
17
- "table" . to_string( )
18
- ) ) ) ) ,
19
- relation
20
- ) ;
11
+ let sql = "DELETE FROM \" table\" " ;
12
+ match verified_stmt ( sql) {
13
+ SQLStatement :: SQLDelete { table_name, .. } => {
14
+ assert_eq ! ( SQLObjectName ( vec![ "\" table\" " . to_string( ) ] ) , table_name) ;
21
15
}
22
16
23
17
_ => assert ! ( false ) ,
@@ -26,23 +20,17 @@ fn parse_delete_statement() {
26
20
27
21
#[ test]
28
22
fn parse_where_delete_statement ( ) {
29
- let sql: & str = "DELETE FROM 'table' WHERE name = 5" ;
30
-
31
23
use self :: ASTNode :: * ;
32
24
use self :: SQLOperator :: * ;
33
25
34
- match verified_stmt ( & sql) {
26
+ let sql = "DELETE FROM foo WHERE name = 5" ;
27
+ match verified_stmt ( sql) {
35
28
SQLStatement :: SQLDelete {
36
- relation ,
29
+ table_name ,
37
30
selection,
38
31
..
39
32
} => {
40
- assert_eq ! (
41
- Some ( Box :: new( ASTNode :: SQLValue ( Value :: SingleQuotedString (
42
- "table" . to_string( )
43
- ) ) ) ) ,
44
- relation
45
- ) ;
33
+ assert_eq ! ( SQLObjectName ( vec![ "foo" . to_string( ) ] ) , table_name) ;
46
34
47
35
assert_eq ! (
48
36
SQLBinaryExpr {
You can’t perform that action at this time.
0 commit comments