Skip to content

Support completion for sqlite3 command-line interface #133390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tanloong opened this issue May 4, 2025 · 13 comments
Open

Support completion for sqlite3 command-line interface #133390

tanloong opened this issue May 4, 2025 · 13 comments
Labels
stdlib Python modules in the Lib dir topic-sqlite3 type-feature A feature request or enhancement

Comments

@tanloong
Copy link
Contributor

tanloong commented May 4, 2025

Feature or enhancement

Proposal:

Current sqlite3 CLI lacks tab-completion feature. Hope it can be supported to improve usability.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@tanloong tanloong added the type-feature A feature request or enhancement label May 4, 2025
@StanFromIreland
Copy link
Contributor

This is a minor feature

I would disagree, this would presumably require quite a lot of work to implement and then maintain. Maybe this should be discussion on discourse first?

@tanloong
Copy link
Contributor Author

tanloong commented May 4, 2025

Right. But I think for the moment we can support basic completion which takes not much work but gives big experience enhancement.

@picnixz picnixz added extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels May 4, 2025
@StanFromIreland
Copy link
Contributor

#133393 introduces keyword expansion, but what about name expansion (the part I was originally worried about)?

@tanloong
Copy link
Contributor Author

tanloong commented May 4, 2025

Can we get the name list when connecting to a disk-file database, merge it with keyword list as completion candidates? Also the name list need to be updated on deletion/creation of table/column.

import sqlite3

def get_names(db_path):
    ret = []
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()

    cursor.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")
    tables = [row[0] for row in cursor.fetchall()] # get table names
    ret.extend(tables)

    for table in tables:
        cursor.execute(f"PRAGMA table_info({table})")
        ret.extend(row[1] for row in cursor.fetchall()) # get column names

    conn.close()
    return ret

db_path = '/path/to/db.db'
list_of_names = get_names(db_path)

@StanFromIreland
Copy link
Contributor

StanFromIreland commented May 5, 2025

@hugovk (BDFC ;-) out of curiosity, is this on your list for colorising, it is a good candidate ? I’d take a stab at it once this is merged.

@hugovk
Copy link
Member

hugovk commented May 5, 2025

It's not on my list but sounds like a good candidate. See also #133247 that added syntax highlighting in the REPL and tools like https://github.com/dbcli/litecli.

@StanFromIreland
Copy link
Contributor

sounds like a good candidate.

Opened #133447 :-)

@encukou
Copy link
Member

encukou commented Jun 7, 2025

Unfortunately, there are issues on the buildbots found before, e.g. here.

I spent some time investigating this, but couldn't reproduce locally or in a container. Next week I'll ask the buildbot owner for SSH access to try and see what's going on, but that's better done after the weekend.

The buildbots are only effective if they're kept passing, so I need to revert the commit temporarily.

encukou added a commit to encukou/cpython that referenced this issue Jun 7, 2025
…LI (python#133393)" temporarily

This reverts commit 62b3d2d,
which broke buildbots
@tanloong
Copy link
Contributor Author

tanloong commented Jun 7, 2025

It looks that the @force_not_colorized_test_class does not fix the test failure on Fedora.

encukou added a commit that referenced this issue Jun 7, 2025
@encukou
Copy link
Member

encukou commented Jun 7, 2025

@tanloong Could you open a PR from here, so that you're listed as the main author?

@tanloong
Copy link
Contributor Author

tanloong commented Jun 7, 2025

Got an error message:

Pull request creation failed. Validation failed: must be a collaborator

But it's totally OK, I think authorship is not a big thing. Hope the test failure is not hard to fix.

@encukou
Copy link
Member

encukou commented Jun 7, 2025

Oh. GitHub is too secure...
You can open a PR from your branch, or I'll open one ~Monday.

@tanloong
Copy link
Contributor Author

tanloong commented Jun 7, 2025

I think it will be more convenient for you to push commits if the PR is from you. Waiting for your PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-sqlite3 type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants