Skip to content

Commit 743bb52

Browse files
committed
Replaced unwrap to handle errors without panic
1 parent 329a94c commit 743bb52

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

src/dialect/mysql.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const RESERVED_FOR_TABLE_ALIAS_MYSQL: &[Keyword] = &[
3535
];
3636

3737
/// A [`Dialect`] for [MySQL](https://www.mysql.com/)
38-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
39-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38+
#[derive(Debug, Default)]
4039
pub struct MySqlDialect {}
4140

4241
impl Dialect for MySqlDialect {
@@ -89,11 +88,6 @@ impl Dialect for MySqlDialect {
8988
true
9089
}
9190

92-
/// see <https://dev.mysql.com/doc/refman/8.4/en/comments.html>
93-
fn supports_multiline_comment_hints(&self) -> bool {
94-
true
95-
}
96-
9791
fn parse_infix(
9892
&self,
9993
parser: &mut crate::parser::Parser,
@@ -102,10 +96,14 @@ impl Dialect for MySqlDialect {
10296
) -> Option<Result<crate::ast::Expr, ParserError>> {
10397
// Parse DIV as an operator
10498
if parser.parse_keyword(Keyword::DIV) {
99+
let right = match parser.parse_expr() {
100+
Ok(val) => val,
101+
Err(e) => return Some(Err(e)),
102+
};
105103
Some(Ok(Expr::BinaryOp {
106104
left: Box::new(expr.clone()),
107105
op: BinaryOperator::MyIntegerDivide,
108-
right: Box::new(parser.parse_expr().unwrap()),
106+
right: Box::new(right),
109107
}))
110108
} else {
111109
None
@@ -162,10 +160,6 @@ impl Dialect for MySqlDialect {
162160
true
163161
}
164162

165-
fn supports_select_modifiers(&self) -> bool {
166-
true
167-
}
168-
169163
fn supports_set_names(&self) -> bool {
170164
true
171165
}
@@ -196,11 +190,6 @@ impl Dialect for MySqlDialect {
196190
fn supports_comment_optimizer_hint(&self) -> bool {
197191
true
198192
}
199-
200-
/// See: <https://dev.mysql.com/doc/refman/8.4/en/create-table.html>
201-
fn supports_constraint_keyword_without_name(&self) -> bool {
202-
true
203-
}
204193
}
205194

206195
/// `LOCK TABLES`

src/dialect/sqlite.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use crate::parser::{Parser, ParserError};
3030
/// [`CREATE TABLE`](https://sqlite.org/lang_createtable.html) statement with no
3131
/// type specified, as in `CREATE TABLE t1 (a)`. In the AST, these columns will
3232
/// have the data type [`Unspecified`](crate::ast::DataType::Unspecified).
33-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
34-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
33+
#[derive(Debug, Default)]
3534
pub struct SQLiteDialect {}
3635

3736
impl Dialect for SQLiteDialect {
@@ -89,11 +88,15 @@ impl Dialect for SQLiteDialect {
8988
] {
9089
if parser.parse_keyword(keyword) {
9190
let left = Box::new(expr.clone());
92-
let right = Box::new(match parser.parse_expr() {
93-
Ok(expr) => expr,
91+
let right = match parser.parse_expr() {
92+
Ok(val) => val,
9493
Err(e) => return Some(Err(e)),
95-
});
96-
return Some(Ok(Expr::BinaryOp { left, op, right }));
94+
};
95+
return Some(Ok(Expr::BinaryOp {
96+
left,
97+
op,
98+
right: Box::new(right),
99+
}));
97100
}
98101
}
99102
None

0 commit comments

Comments
 (0)