Skip to content

Commit

Permalink
Fix panic on unknown table option
Browse files Browse the repository at this point in the history
Fix #44
  • Loading branch information
gwenn committed Mar 16, 2024
1 parent 24043e9 commit a7cd0c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/lexer/sql/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ fn natural_join_on() {
);
}

#[test]
fn unknown_table_option() {
expect_parser_err_msg(b"CREATE TABLE t(x)o", "unknown table option: o");
expect_parser_err_msg(b"CREATE TABLE t(x) WITHOUT o", "unknown table option: o");
}

fn expect_parser_err_msg(input: &[u8], error_msg: &str) {
expect_parser_err(input, ParserError::Custom(error_msg.to_owned()))
}
Expand Down
15 changes: 7 additions & 8 deletions src/parser/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
// code file that implements the parser.
//
%include {
use crate::custom_err;
use crate::parser::ast::*;
use crate::parser::{Context, ParserError};
use crate::dialect::{from_token, Token, TokenType};
Expand Down Expand Up @@ -140,21 +141,19 @@ table_option_set(A) ::= . {A = TableOptions::NONE;}
table_option_set(A) ::= table_option(A).
table_option_set(A) ::= table_option_set(X) COMMA table_option(Y). {A = X|Y;}
table_option(A) ::= WITHOUT nm(X). {
if "rowid".eq_ignore_ascii_case(&X.0) {
let option = X;
if "rowid".eq_ignore_ascii_case(&option.0) {
A = TableOptions::WITHOUT_ROWID;
}else{
A = TableOptions::NONE;
let msg = format!("unknown table option: {}", &X);
self.ctx.sqlite3_error_msg(&msg);
return Err(custom_err!("unknown table option: {}", option));
}
}
table_option(A) ::= nm(X). {
if "strict".eq_ignore_ascii_case(&X.0) {
let option = X;
if "strict".eq_ignore_ascii_case(&option.0) {
A = TableOptions::STRICT;
}else{
A = TableOptions::NONE;
let msg = format!("unknown table option: {}", &X);
self.ctx.sqlite3_error_msg(&msg);
return Err(custom_err!("unknown table option: {}", option));
}
}
%type columnlist {Vec<ColumnDefinition>}
Expand Down

0 comments on commit a7cd0c1

Please sign in to comment.