GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-133390: Extend completion for .commands in `sqlite3` by StanFromIreland · Pull Request #135432 · python/cpython

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Jun 12, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@tanloong @encukou

  • Issue: Support completion for sqlite3 command-line interface #133390

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@StanFromIreland
Add completion for .commands
39ba777
@StanFromIreland
StanFromIreland requested review from berkerpeksag and erlend-aasland as code owners June 12, 2025 15:26
@bedevere-app bedevere-app Bot added the awaiting review label Jun 12, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 12, 2025
Support completion for sqlite3 command-line interface #133390
Closed
tanloong
tanloong reviewed Jun 12, 2025
View reviewed changes

@tanloong tanloong left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Only commands with a dot at the line beginning is considered dot commands. text is the non-whitespace chars under wherever the cursor is at. This means using text.startswith() enables dot command completion for not only actual dot commands but also any inline word that starts with dot:

sqlite> SELECT .<tab>
.help 
.quit 
.version 
sqlite> SELECT .

Using readline.get_line_buffer() instead is more reasonable. This returns the whole current line and can be used to avoid completion for dot-started inline word:

origline = readline.get_line_buffer()
if origline.startswith("."):
    ...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@StanFromIreland

StanFromIreland commented Jun 12, 2025

Copy link
Copy Markdown
Member Author

sqlite3 identifiers cannot start with . (OperationalError (SQLITE_ERROR): near ".": syntax error). Calling readline would complicate our imports a bit more, I'm not sure it is worth it. Not much changes, it is invalid just like it was before.

tanloong reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tanloong

tanloong commented Jun 12, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I actually also made a local change to add dot commands completion. This is the idea on my local branch, just sharing it for discussion:

  1. Complete without dot if there is any number of whitespaces between the dot and the cursor.
sqlite> . |
help
version
quit
  1. Complete with the dot if cursor is immediately at the right handside of the dot.
sqlite> .|
.help
.version
.quit
  1. Complete nothing if there is any non-whitespace chars between the dot and the cursor (as we currently don't have dot commands that receive arguments).
sqlite> . help |
# no candidates
COMMANDS = ("quit", "help", "version")


def _complete(text, state):
    global _completion_matches

    if state == 0:
        import readline

        origline = readline.get_line_buffer()
        if origline.startswith("."):
            if origline == text:
                text_lstrip = text.lstrip(".")
                _completion_matches = [f".{cmd}" for cmd in COMMANDS
                                       if cmd.startswith(text_lstrip)]
            elif origline.removeprefix(".").lstrip(" ") == text:
                _completion_matches = [cmd for cmd in COMMANDS
                                       if cmd.startswith(text)]
            else:
                _completion_matches.clear()
        else:
            text_upper = text.upper()
            _completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
    try:
        return _completion_matches[state] + " "
    except IndexError:
        return None
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou reviewed Aug 22, 2025
View reviewed changes
Comment thread Lib/sqlite3/_completer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland
Requested changes
82ff87e
@StanFromIreland
StanFromIreland requested a review from encukou August 22, 2025 09:22
@StanFromIreland StanFromIreland added the skip news label Aug 22, 2025
@encukou

encukou commented Aug 25, 2025

Copy link
Copy Markdown
Member

Thank you!
@tanloong, additional improvements are welcome :)

tanloong reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou
encukou merged commit a553065 into python:main Aug 25, 2025
@bedevere-app bedevere-app Bot removed the awaiting review label Aug 25, 2025
@StanFromIreland
StanFromIreland deleted the sqlite3-.commands branch August 25, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@berkerpeksag berkerpeksag Awaiting requested review from berkerpeksag
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@encukou encukou Awaiting requested review from encukou
1 more reviewer
@tanloong tanloong tanloong left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@StanFromIreland @tanloong @encukou
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.