Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dialect/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ impl Dialect for SQLiteDialect {
fn get_next_precedence(&self, parser: &Parser) -> Option<Result<u8, ParserError>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2559 carries this same Token::Colon arm; keep it here and drop it from #2559 so the two don't double-define get_next_precedence when both land.

match parser.peek_token_ref().token {
Token::Ampersand | Token::Pipe => Some(Ok(self.prec_value(Precedence::Ampersand))),
// lowest prec to prevent it from turning into a binary op
Token::Colon => Some(Ok(self.prec_unknown())),
_ => None,
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/sqlparser_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,31 @@ fn parse_unterminated_block_comment() {
);
}

#[test]
fn parse_colon_does_not_start_json_access() {
// SQLite rejects `SELECT c:se` (`near ":se": syntax error`); no `:` traversal.
for sql in ["SELECT c:se", "SELECT a:b FROM t"] {
assert_eq!(
sqlite().parse_sql_statements(sql),
Err(ParserError::ParserError(
"Expected: end of statement, found: :".to_string()
))
);
}

let ast = sqlite().verified_only_select("SELECT :xxx");
assert_eq!(
ast.projection[0],
UnnamedExpr(Expr::Value(
(Value::Placeholder(":xxx".into())).with_empty_span()
)),
);

TestedDialects::new(vec![Box::new(GenericDialect {})])
.parse_sql_statements("SELECT a:b FROM t")
.unwrap();
}

fn sqlite() -> TestedDialects {
TestedDialects::new(vec![Box::new(SQLiteDialect {})])
}
Expand Down
Loading