Skip to content

Commit

Permalink
Return error when AUTO_INCRMENT offset is too large
Browse files Browse the repository at this point in the history
Closes #1303
  • Loading branch information
eejbyfeldt committed Jun 10, 2024
1 parent be77ce5 commit 564b401
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5281,7 +5281,12 @@ impl<'a> Parser<'a> {
let _ = self.consume_token(&Token::Eq);
let next_token = self.next_token();
match next_token.token {
Token::Number(s, _) => Some(s.parse::<u32>().expect("literal int")),
Token::Number(s, _) => Some(s.parse::<u32>().map_err(|e| {
ParserError::ParserError(format!(
"Could not parse '{s}' as u32: {e}{}",
next_token.location
))
})?),
_ => self.expected("literal int", next_token)?,
}
} else {
Expand Down
14 changes: 14 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9991,3 +9991,17 @@ fn parse_select_wildcard_with_except() {
"sql parser error: Expected identifier, found: )"
);
}

#[test]
fn parse_auto_increment_too_large() {
let dialect = GenericDialect {};
let u64_max = u64::MAX;
let sql = format!("CREATE TABLE foo (bar INT NOT NULL AUTO_INCREMENT) AUTO_INCREMENT=1{u64_max}");

let res = Parser::new(&dialect)
.try_with_sql(&sql)
.expect("tokenize to work")
.parse_statements();

assert!(res.is_err(), "{res:?}");
}

0 comments on commit 564b401

Please sign in to comment.