Skip to content

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

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

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

Conversation

@Tony123-tech

Copy link
Copy Markdown
Contributor

Fixes gh-158277.

def test_complete_view_columns(self):
input_ = textwrap.dedent("""\
CREATE TABLE _table (_col_table);
CREATE VIEW _view AS SELECT _col_view AS _col_view_alias,

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.

Need to remove the _col_view AS _col_view_alias, as _table does not contain the _col_view column.

@unittest.skipIf(sqlite3.sqlite_version_info < (3, 30, 0),
"PRAGMA function_list is not available until "
"SQLite 3.30.0")
def test_complete_view_columns(self):

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.

test_complete_view_columns() appears to have taken over the decorator intended for test_complete_functions(). Would it be better to put this test into the existing test_complete_columns()? That keeps the functionality tests together.

@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"]
        )

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite3 CLI completer: include views in column completion

2 participants