-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-133390: Support SQL keyword completion for sqlite3 CLI (#133393) #135292
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10f822b
gh-133390: Support SQL keyword completion for sqlite3 CLI (#133393)
tanloong a59ec6a
Pass env variables to test subprocess
encukou bd6a870
Import unittest.mock, so test_sqlite3.test_cli works on its own
encukou 3d9721a
Dump output on error in verbose mode
encukou f1fa6c7
Disable readline's show-all settings
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from contextlib import contextmanager | ||
|
||
try: | ||
from _sqlite3 import SQLITE_KEYWORDS | ||
except ImportError: | ||
SQLITE_KEYWORDS = () | ||
|
||
_completion_matches = [] | ||
|
||
|
||
def _complete(text, state): | ||
global _completion_matches | ||
|
||
if state == 0: | ||
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 | ||
|
||
|
||
@contextmanager | ||
def completer(): | ||
try: | ||
import readline | ||
except ImportError: | ||
yield | ||
return | ||
|
||
old_completer = readline.get_completer() | ||
try: | ||
readline.set_completer(_complete) | ||
if readline.backend == "editline": | ||
# libedit uses "^I" instead of "tab" | ||
command_string = "bind ^I rl_complete" | ||
else: | ||
command_string = "tab: complete" | ||
readline.parse_and_bind(command_string) | ||
yield | ||
finally: | ||
readline.set_completer(old_completer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2025-05-05-03-14-08.gh-issue-133390.AuTggn.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support keyword completion in the :mod:`sqlite3` command-line interface. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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 is unused, no?
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.
It's used on line 203.
If you run
python -m test test_sqlite3
, tests would pass because something else sets themock
attribute onunittest
. But running onlypython -m test test_sqlite3.test_cli
failed.