Repository navigation
Conversation
Resolves cs50#199 by: - Recognizing PRAGMA statements during command parsing (sqlparse parses PRAGMA as an Identifier rather than a generic SQL keyword). - Adding PRAGMA to supported commands. - Bypassing autocommit transaction wrapping for PRAGMA statements (some PRAGMAs cannot be executed inside transactions, e.g., WAL mode). - Consuming statement results before committing when results return rows, preventing 'cannot commit transaction - SQL statements in progress'. - Returning formatted list-of-dicts result rows for querying PRAGMAs (e.g., journal_mode, table_info, foreign_keys) and True for configuration PRAGMAs. - Adding comprehensive test_pragma coverage in SQLiteTests. Signed-off-by: Rajnish Singh <rajnisihsingh@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #199 by adding support for SQLite
PRAGMAstatements incs50.SQL.Problem & Root Cause
sqlparse,PRAGMAis tokenized as anIdentifier(Token.Name) rather than a standard DDL/DML keyword (Token.Keyword). Consequently,full_statementevaluated to an empty string, andcommandwas parsed asNone.self._autocommit = True),cs50.SQLwrapped the query inBEGIN...COMMIT. CertainPRAGMAdirectives (such asPRAGMA journal_mode = WAL) cannot be executed within a transaction. Furthermore, forPRAGMAqueries that return rows (such asPRAGMA journal_modeorPRAGMA table_info(...)), callingCOMMITwhile statement result rows remain unconsumed raisessqlite3.OperationalError: cannot commit transaction - SQL statements in progress.command != "SELECT", any rows returned by querying PRAGMAs were discarded, returningTrueinstead of the result set.Solution
PRAGMAstatements case-insensitively, and add"PRAGMA"tocommands.BEGIN/COMMIT) forPRAGMAstatements, allowing configuration PRAGMAs to execute cleanly.SELECTor anyPRAGMAreturning rows (result.returns_rows).test_pragmacovering row-returning PRAGMAs (PRAGMA journal_mode,PRAGMA foreign_keys,PRAGMA table_info), configuration PRAGMAs (PRAGMA foreign_keys = ON), and commented statements. All 23 SQLite unit tests pass.Closes #199.