diff --git a/src/sqlast/mod.rs b/src/sqlast/mod.rs index c5e85c09..1461726d 100644 --- a/src/sqlast/mod.rs +++ b/src/sqlast/mod.rs @@ -76,7 +76,7 @@ pub enum ASTNode { }, /// A parenthesized subquery `(SELECT ...)`, used in expression like /// `SELECT (subquery) AS x` or `WHERE (subquery) = x` - SQLSubquery(SQLSelect), + SQLSubquery(Box), } impl ToString for ASTNode { diff --git a/src/sqlast/query.rs b/src/sqlast/query.rs index 385173a1..887042f9 100644 --- a/src/sqlast/query.rs +++ b/src/sqlast/query.rs @@ -6,18 +6,18 @@ pub struct SQLSelect { pub projection: Vec, /// FROM pub relation: Option, - // JOIN + /// JOIN pub joins: Vec, /// WHERE - pub selection: Option>, + pub selection: Option, /// ORDER BY pub order_by: Option>, /// GROUP BY pub group_by: Option>, /// HAVING - pub having: Option>, + pub having: Option, /// LIMIT - pub limit: Option>, + pub limit: Option, } impl ToString for SQLSelect { @@ -37,7 +37,7 @@ impl ToString for SQLSelect { s += &join.to_string(); } if let Some(ref selection) = self.selection { - s += &format!(" WHERE {}", selection.as_ref().to_string()); + s += &format!(" WHERE {}", selection.to_string()); } if let Some(ref group_by) = self.group_by { s += &format!( @@ -50,7 +50,7 @@ impl ToString for SQLSelect { ); } if let Some(ref having) = self.having { - s += &format!(" HAVING {}", having.as_ref().to_string()); + s += &format!(" HAVING {}", having.to_string()); } if let Some(ref order_by) = self.order_by { s += &format!( @@ -63,7 +63,7 @@ impl ToString for SQLSelect { ); } if let Some(ref limit) = self.limit { - s += &format!(" LIMIT {}", limit.as_ref().to_string()); + s += &format!(" LIMIT {}", limit.to_string()); } s } diff --git a/src/sqlparser.rs b/src/sqlparser.rs index b72e8fbc..f2d616cc 100644 --- a/src/sqlparser.rs +++ b/src/sqlparser.rs @@ -197,7 +197,7 @@ impl Parser { } Token::LParen => { let expr = if self.parse_keyword("SELECT") { - ASTNode::SQLSubquery(self.parse_select()?) + ASTNode::SQLSubquery(Box::new(self.parse_select()?)) } else { ASTNode::SQLNested(Box::new(self.parse_expr()?)) }; @@ -1129,7 +1129,7 @@ impl Parser { let selection = if self.parse_keyword("WHERE") { let expr = self.parse_expr()?; - Some(Box::new(expr)) + Some(expr) } else { None }; @@ -1141,7 +1141,7 @@ impl Parser { }; let having = if self.parse_keyword("HAVING") { - Some(Box::new(self.parse_expr()?)) + Some(self.parse_expr()?) } else { None }; @@ -1374,12 +1374,12 @@ impl Parser { } /// Parse a LIMIT clause - pub fn parse_limit(&mut self) -> Result>, ParserError> { + pub fn parse_limit(&mut self) -> Result, ParserError> { if self.parse_keyword("ALL") { Ok(None) } else { self.parse_literal_int() - .map(|n| Some(Box::new(ASTNode::SQLValue(Value::Long(n))))) + .map(|n| Some(ASTNode::SQLValue(Value::Long(n)))) } } } diff --git a/tests/sqlparser_generic.rs b/tests/sqlparser_generic.rs index 3921ea60..0d613469 100644 --- a/tests/sqlparser_generic.rs +++ b/tests/sqlparser_generic.rs @@ -54,7 +54,7 @@ fn parse_simple_select() { projection, limit, .. }) => { assert_eq!(3, projection.len()); - assert_eq!(Some(Box::new(ASTNode::SQLValue(Value::Long(5)))), limit); + assert_eq!(Some(ASTNode::SQLValue(Value::Long(5))), limit); } _ => assert!(false), } @@ -207,7 +207,7 @@ fn parse_like() { "%a".to_string() ))), }, - *selection.unwrap() + selection.unwrap() ); } _ => assert!(false), @@ -227,7 +227,7 @@ fn parse_not_like() { "%a".to_string() ))), }, - *selection.unwrap() + selection.unwrap() ); } _ => assert!(false), @@ -287,7 +287,7 @@ fn parse_select_order_by_limit() { ]), order_by ); - assert_eq!(Some(Box::new(ASTNode::SQLValue(Value::Long(2)))), limit); + assert_eq!(Some(ASTNode::SQLValue(Value::Long(2))), limit); } _ => assert!(false), }