Skip to content

SQLite: parse the full PRAGMA value grammar - #2469

Open
LucaCappelletti94 wants to merge 2 commits into
apache:mainfrom
LucaCappelletti94:sqlite-pragma-boolean-values
Open

SQLite: parse the full PRAGMA value grammar#2469
LucaCappelletti94 wants to merge 2 commits into
apache:mainfrom
LucaCappelletti94:sqlite-pragma-boolean-values

Conversation

@LucaCappelletti94

@LucaCappelletti94 LucaCappelletti94 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

PRAGMA values such as journal_mode = WAL, synchronous = NORMAL, cache_size = -2000 and optimize = 0x10002 were rejected. The earlier boolean handling also kept its own keyword list plus a value-type allowlist, and that duplicated allowlist is what rejected PRAGMA case_sensitive_like = true in the first place.

parse_pragma_value now follows SQLite's own definition of a pragma value, signed-number | name | signed-literal, and stores the result as an Expr. A bare name like WAL is kept as an identifier, so the parser no longer decides which value a given pragma accepts and leaves that to execution the way SQLite does. parse_pragma builds the statement in a single place.

This changes Statement::Pragma.value from Option<ValueWithSpan> to Option<Expr>.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review August 31, 2026 13:28
Comment thread src/parser/mod.rs Outdated
Comment on lines +20170 to +20197
let span = self.peek_token_ref().span;
let v = match self.parse_one_of_keywords(&[
Keyword::TRUE,
Keyword::FALSE,
Keyword::ON,
Keyword::OFF,
Keyword::YES,
Keyword::NO,
]) {
Some(keyword) => Value::Boolean(matches!(
keyword,
Keyword::TRUE | Keyword::YES | Keyword::ON
))
.with_span(span),
None => self.parse_value()?,
};
match &v.value {
Value::SingleQuotedString(_) => Ok(v),
Value::DoubleQuotedString(_) => Ok(v),
Value::Number(_, _) => Ok(v),
Value::Boolean(_) => Ok(v),
Value::Placeholder(_) => Ok(v),
_ => {
self.prev_token();
self.expected_ref("number or string or ? placeholder", self.peek_token_ref())
self.expected_ref(
"boolean, number, string, or ? placeholder",
self.peek_token_ref(),
)

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.

I think we could simplify the logic to have it accept whatever parse_value returns. and keep the sqlite semantics for validation upstream? that would have avoided this bug in the initial version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I checked SQLite docs hoping for a limited set of allowed values, it states there is explicitly no such set, and I therefore switched to Expr

@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-pragma-boolean-values branch from 0fa5f24 to 4dfcf28 Compare September 7, 2026 05:19
@LucaCappelletti94 LucaCappelletti94 changed the title Parse SQLite boolean PRAGMA values SQLite: parse the full PRAGMA value grammar Sep 7, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-pragma-boolean-values branch from 4dfcf28 to 582c4e4 Compare September 7, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants