gh-135795: Support .tables in the sqlite3 command-line interface#135796
Open
tanloong wants to merge 9 commits intopython:mainfrom
Open
gh-135795: Support .tables in the sqlite3 command-line interface#135796tanloong wants to merge 9 commits intopython:mainfrom
.tables in the sqlite3 command-line interface#135796tanloong wants to merge 9 commits intopython:mainfrom
Conversation
Contributor
Author
|
I happen to notice that the LIKE pattern |
Contributor
|
It seems that |
…p text for consistency; simplify view creation in test case
bac35fa to
6deb0ea
Compare
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.
This adds
.tablesto list table names in the current database connection.The output is made similar to that of SQLite tool to give users familiar experience. Both tables and views, whether temporary or not, are included in the output. Tables with names like
sqlite_%(which is reserved by SQLite for internal use) are filtered out. Table names from themainschema are shown as is, while those from other schemas are shown with a schema-name prefix. For example, temporary tabletmpis shown astemp.tmp.The SQLite tool allows an optional
TABLEargument with.tablesto filter table names with LIKE pattern TABLE. This feature is not included because the SQLite standard of argument handling for dot commands is too complex, I am worried about overcomplicating the code in this single PR.A connection has three kinds of databases: the main database; the temporary database used to store temporary tables/views etc; attached databases added to current connection using the
ATTACHcommand. Schema-names of all these three can be obtained byPRAGMA database_list. For historical compatibility,{schema-name}.sqlite_masterinstead of{schema-name}.sqlite_schemais used to get table names. The CPythonsqlite3module accepts SQLite>=3.15.2, butsqlite_schemawas not added in SQLite until 3.33.0.In the
select_clausesgenerator, the inconsistent usage of double- and single-quotes is intentional. The SQL standard requires double-quotes around identifiers and single-quotes around string literals. The double quotes in"{schema}"are to ensure thatschemais recognized as an identifier even if user attaches a database with a numeric schema name, e.g.,ATTACH '/path/to/db' AS 123;. This corner case is included in thetest_interact_tables().