Skip to content

gh-158277: sqlite3 CLI completer: include views in column completion - #158278

Open
Tony123-tech wants to merge 3 commits into
python:mainfrom
Tony123-tech:gh-158277-sqlite3-completer-views
Open

Tony123-tech wants to merge 3 commits into
python:mainfrom
Tony123-tech:gh-158277-sqlite3-completer-views

Conversation

@Tony123-tech

Copy link
Copy Markdown
Contributor

Fixes gh-158277.

Comment thread Lib/test/test_sqlite3/test_cli.py Outdated
Comment thread Lib/test/test_sqlite3/test_cli.py Outdated
@Tony123-tech

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've fixed both issues:

  1. Added _col_view to the _table definition
  2. Changed the decorator to the correct SQLite version (3.16.0 for pragma_table_xinfo)

@tanloong

Copy link
Copy Markdown
Contributor
  1. The extra _col_view_alias column check in test_complete_view_columns() provides no more infomation than _col_table_alias. Asserting _col_table_alias alone in the candidates is enough for test purpose. How about removing the _col_view_alias and _col_view definition:
CREATE TABLE _table (_col_table);
CREATE VIEW _view AS SELECT _col_table AS _col_table_alias FROM _table;
  1. The @unittest.skipIf(sqlite3.sqlite_version_info < (3, 16, 0), ...) decorator, which is originally for test_complete_functions(), is occupied by the newly added test_complete_view_columns() in this PR. How about replace the test_complete_view_columns() with new tests in the already existing test_complete_columns() like this:
    def test_complete_columns(self):
        input_ = textwrap.dedent("""\
            CREATE TABLE _table (_col_table);
            CREATE TEMP TABLE _temp_table (_col_temp);
+           CREATE VIEW _view AS SELECT _col_table AS _col_table_alias FROM _table;
            ATTACH ':memory:' AS attached;
            CREATE TABLE attached._attached_table (_col_attached);

            SELECT _col_\t\tta\tFROM _table;
            .quit\n""").encode()
        output = self.write_input(input_)
        lines = output.decode().splitlines()
        indices = [
            i for i, line in enumerate(lines) if line.startswith(self.PS1)
        ]
        start, end = indices[-3], indices[-2]
        candidates = [l.strip() for l in lines[start+1:end]]

        self.assertEqual(
-           candidates, ["_col_attached", "_col_table", "_col_temp"]
+           candidates, ["_col_attached", "_col_table", "_col_table_alias", "_col_temp"]
        )

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Sep 28, 2026
@tanloong

Copy link
Copy Markdown
Contributor

Looks good to me. Let's wait for erlend-aasland's review as he is the module maintainer, he might ask for some changes, in which case I'm sorry if I suggested something wrong.

@Tony123-tech

Copy link
Copy Markdown
Contributor Author

@tanloong @erlend-aasland The "Unresolved review" check is failing
because the two review comments from 2 weeks ago are still open. I've
addressed both points in 0d647bb (the comments are marked outdated).
Could one of you resolve them, or let me know if there's something
else that needs to change?

@encukou encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me; I'll merge ~Friday if there are no objections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite3 CLI completer: include views in column completion

3 participants