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: Support SQL keyword completion for sqlite3 CLI by tanloong · Pull Request #133393 · python/cpython

Conversation

@tanloong

@tanloong tanloong commented May 4, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This adds tab-completion for the 147 SQLite Keywords. A whitespace is appended to completion candidates for users' convenience and to mimic the behavior of sqlite3 tool.

  • 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
@tanloong
tanloong requested review from berkerpeksag and erlend-aasland as code owners May 4, 2025 19:05
@python-cla-bot

python-cla-bot Bot commented May 4, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented May 4, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot mentioned this pull request May 4, 2025
Support completion for sqlite3 command-line interface #133390
Closed
@bedevere-app bedevere-app Bot added the awaiting review label May 4, 2025
StanFromIreland
StanFromIreland reviewed May 4, 2025
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

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.

This needs a whatsnew entry, (maybe a note in the docs?), a NEWS entry and tests.

This is quite limited completion so I guess it could work.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/sqlite3/__main__.py Resolved

Uh oh!

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

@picnixz

picnixz commented May 4, 2025

Copy link
Copy Markdown
Member

I think we need a separate nodule for this because if we want to have a smarter completion later the code is better to be isolated, so something like sqlite3._completer.

If possible, can we have an autogenerated list of keywords? and those keywords could also be stored in a (private) module-level list.

All reactions

Sorry, something went wrong.

Uh oh!

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

picnixz
picnixz reviewed May 4, 2025
View reviewed changes
Comment thread Lib/sqlite3/__main__.py Resolved

Uh oh!

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

Comment thread Lib/sqlite3/__main__.py Resolved

Uh oh!

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

Comment thread Misc/NEWS.d/next/Library/2025-05-05-03-14-08.gh-issue-133390.AuTggn.rst Resolved

Uh oh!

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

@picnixz

picnixz commented May 4, 2025

Copy link
Copy Markdown
Member

Please add tests

All reactions

Sorry, something went wrong.

Uh oh!

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

@tanloong

tanloong commented May 4, 2025

Copy link
Copy Markdown
Contributor Author

Yes, tests is coming. I will try to find a way to autogenerate list of keywords.

picnixz 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.

@StanFromIreland

StanFromIreland commented May 4, 2025

Copy link
Copy Markdown
Member

You can mark the pr as a draft.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tanloong
tanloong marked this pull request as draft May 4, 2025 21:23
@bedevere-app bedevere-app Bot removed the awaiting review label May 4, 2025
StanFromIreland
StanFromIreland reviewed May 4, 2025
View reviewed changes
Comment thread Lib/sqlite3/_completer.py Resolved

Uh oh!

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

Comment thread Lib/sqlite3/_completer.py Resolved

Uh oh!

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

Comment thread Doc/whatsnew/3.14.rst Resolved

Uh oh!

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

@tanloong
tanloong force-pushed the sqlite3-cli-completion branch 8 times, most recently from 782a599 to 5005d85 Compare May 5, 2025 04:47
@tanloong

tanloong commented May 5, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Added tests and moved keyword list to module level.

Keywords seems not easy to auto-generate, the SQLite document says they can be accessed by sqlite3_keyword_count() and sqlite3_keyword_name() using C, but I am bad at C and didn't figure out how to call these two at Python level. I think these two functions are not exposed to Python?

All reactions

Sorry, something went wrong.

Uh oh!

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

@tanloong
tanloong marked this pull request as ready for review May 5, 2025 05:08
@bedevere-app bedevere-app Bot added the awaiting review label May 5, 2025
@StanFromIreland StanFromIreland mentioned this pull request May 5, 2025
Colorize sqlite3 CLI #133447
Closed
StanFromIreland
StanFromIreland reviewed May 5, 2025
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

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.

With #133447 in mind the keywords list would be quite handy (I think hardcoding is fine, it doesn't change often anyway). Maybe it could be moved elsewhere, what do you think Benedikt?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/whatsnew/3.14.rst Resolved

Uh oh!

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

Comment thread Lib/sqlite3/_completer.py Resolved

Uh oh!

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

@tanloong
tanloong force-pushed the sqlite3-cli-completion branch from 15019ea to 22652ae Compare May 5, 2025 18:20
@tanloong

tanloong commented May 5, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Hi @picnixz, as Stan mentioned, beta freeze is around the corner, but I really hope this can be shipped in 3.14, do you think there is a chance to merge it before beta freeze?

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot

bedevere-bot commented Jun 5, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit d681425 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133393%2Fmerge

The command will test the builders whose names match following regular expression: AMD64.Fedora.Stable.PR

The builders matched are:

  • AMD64 Fedora Stable PR
All reactions

Sorry, something went wrong.

Uh oh!

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

tanloong added 2 commits June 5, 2025 20:57
@tanloong
Add two '\b\b'; Skip tests on FreeBSD
ffd0f02
@tanloong
Amend skipping reason
6188a6d
erlend-aasland
erlend-aasland reviewed Jun 5, 2025
View reviewed changes
Comment thread Modules/_sqlite/module.c Resolved

Uh oh!

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

erlend-aasland
erlend-aasland reviewed Jun 5, 2025
View reviewed changes
Comment thread Modules/_sqlite/module.c Resolved

Uh oh!

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

tanloong added 3 commits June 5, 2025 22:36
@tanloong
Remove comment 'set the keyword tuple'
370dd8b
@tanloong
Disable keyword completion for SQLite<3.24.0
16b1674
@tanloong
Don't disable the whole completion in case there will be more completion
ea108ba
sources added which might be available for even old SQLite.
serhiy-storchaka
serhiy-storchaka reviewed Jun 5, 2025
View reviewed changes
Comment thread Modules/_sqlite/module.c Resolved

Uh oh!

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

tanloong added 2 commits June 5, 2025 23:24
@tanloong
Use compile-time check
13b527e
@tanloong
Correct #if usage
fafd1bb
serhiy-storchaka
serhiy-storchaka reviewed Jun 5, 2025
View reviewed changes
Comment thread Modules/_sqlite/module.c Resolved

Uh oh!

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

@tanloong
Wrap add_keyword_tuple() definition and its call in #if/#endif
140818c
serhiy-storchaka
serhiy-storchaka reviewed Jun 5, 2025
View reviewed changes
Comment thread Modules/_sqlite/module.c Resolved

Uh oh!

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

erlend-aasland and others added 3 commits June 6, 2025 13:00
@erlend-aasland
Suggestions to python#133393
fd6c89e
@tanloong
Merge pull request #3 from erlend-aasland/suggestion
588fb6a
Suggestions to python#133393
@erlend-aasland
Merge branch 'main' into sqlite3-cli-completion
5623f16
erlend-aasland
erlend-aasland reviewed Jun 6, 2025
View reviewed changes
Comment thread Modules/_sqlite/module.c
for (int i = 0; i < count; i++) {
const char *keyword;
int size;
int result = sqlite3_keyword_name(i, &keyword, &size);

@erlend-aasland erlend-aasland Jun 6, 2025

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.

For the record:
We could just assert that the result is SQLITE_OK. This is just an out-of-bounds check, and we know that we are within bounds here. OTOH, we don't know how the SQLite internals may change, so let's keep it like it is.

Sorry, something went wrong.

Uh oh!

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

All reactions
@erlend-aasland

erlend-aasland commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

FTR, CI fails bco. #134077. Let's await a revert or a fix for that.

Otherwise, this looks great. Thank you so much for improving the sqlite3 module, @tanloong. Highly appreciated!

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.

erlend-aasland
erlend-aasland approved these changes Jun 6, 2025
View reviewed changes
erlend-aasland
erlend-aasland reviewed Jun 6, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

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

erlend-aasland and others added 2 commits June 6, 2025 14:23
@erlend-aasland
Update Doc/whatsnew/3.15.rst
88c8d59
@erlend-aasland
Merge branch 'main' into sqlite3-cli-completion
b3a2b88
@erlend-aasland

erlend-aasland commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

FTR, I've tested this with new SQLite variants, as well as SQLite 3.23.0 and 3.24.0. Everything works as expected for all versions. I should really get to setting up a build-bot with a SQLite library matrix.

stonebig reacted with hooray emoji encukou reacted with heart emoji
All reactions
  • 🎉 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland

erlend-aasland commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

I only get the "Display all 147 possibilities? (y or n)" prompt with editline, and never on readline. Probably a bug in readline? Or are we missing a configuration option in order to get this to work?

All reactions

Sorry, something went wrong.

Uh oh!

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

@tanloong

tanloong commented Jun 6, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Readline has a completion-query-items (default value 100) option to determine whether or when this prompt should be shown. https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html#index-completion_002dquery_002ditems

With a default readline config the prompt should have be shown, I suspect there is a config that sets the option to 0 on the testing machine?

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland

erlend-aasland commented Jun 6, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

With a default readline config the prompt should have be shown, I suspect there is a config that sets the option to 0 on the testing machine?

Nope. I was a little bit vague in my previous comment: I see the text "Display all 147 possibilities? (y or n)", but it is not shown as a prompt after the first tab. It is only displayed together with the resulting completion list, after the second tab.

IOW: For editline, I get the prompt on the first tab; for readline, I get no prompt, but I see the prompt text after the second tab.

FTR, I already experimented with the completion-query-items option, and it has no impact.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tanloong

tanloong commented Jun 6, 2025

Copy link
Copy Markdown
Contributor Author

Try set show-all-if-unmodified on in readline and see if it make the prompt shown on just the first tab? https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html#index-show_002dall_002dif_002dunmodified

All reactions

Sorry, something went wrong.

Uh oh!

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

erlend-aasland
erlend-aasland reviewed Jun 6, 2025
View reviewed changes
Comment thread Lib/sqlite3/_completer.py Resolved

Uh oh!

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

@tanloong

tanloong commented Jun 6, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Thank you very much for the careful review and thorough test! There are so many corners and difficulties that I would have never considered let alone solved, thanks for everyone's help!

All reactions

Sorry, something went wrong.

Uh oh!

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

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

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@picnixz picnixz picnixz approved these changes
@erlend-aasland erlend-aasland erlend-aasland approved these changes
@StanFromIreland StanFromIreland StanFromIreland left review comments
@encukou encukou encukou left review comments

Uh oh!

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

Assignees

@erlend-aasland erlend-aasland

Labels

topic-sqlite3

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.

8 participants

@tanloong @picnixz @StanFromIreland @bedevere-bot @encukou @erlend-aasland @serhiy-storchaka @ZeroIntensity
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.