Skip to content

Commit c00d96c

Browse files
[3.14] gh-139105: Correct the EOF key shown on Windows in sqlite3's .help (GH-139106)
(cherry picked from commit 7515b64) Co-authored-by: Keming <kemingy94@gmail.com> Signed-off-by: Keming <kemingy94@gmail.com> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 5d615fb commit c00d96c

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎Lib/sqlite3/__main__.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from textwrap import dedent
1313

1414

15+
# IDLE uses CTRL-D for EOF on all platforms (gh-102628).
16+
if sys.platform == "win32" and "idlelib.run" not in sys.modules:
17+
EOF_KEY = "CTRL-Z"
18+
else:
19+
EOF_KEY = "CTRL-D"
20+
21+
1522
def execute(c, sql, suppress_errors=True):
1623
"""Helper that wraps execution of SQL code.
1724
@@ -102,16 +109,12 @@ def main(*args):
102109
db_name = repr(args.filename)
103110

104111
# Prepare REPL banner and prompts.
105-
if sys.platform == "win32" and "idlelib.run" not in sys.modules:
106-
eofkey = "CTRL-Z"
107-
else:
108-
eofkey = "CTRL-D"
109112
banner = dedent(f"""
110113
sqlite3 shell, running on SQLite version {sqlite3.sqlite_version}
111114
Connected to {db_name}
112115
113116
Each command will be run using execute() on the cursor.
114-
Type ".help" for more information; type ".quit" or {eofkey} to quit.
117+
Type ".help" for more information; type ".quit" or {EOF_KEY} to quit.
115118
""").strip()
116119
sys.ps1 = "sqlite> "
117120
sys.ps2 = " ... "

‎Lib/test/test_sqlite3/test_cli.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""sqlite3 CLI tests."""
22
import sqlite3
3+
import sys
34
import unittest
45

56
from sqlite3.__main__ import main as cli
@@ -73,6 +74,7 @@ class InteractiveSession(unittest.TestCase):
7374
MEMORY_DB_MSG = "Connected to a transient in-memory database"
7475
PS1 = "sqlite> "
7576
PS2 = "... "
77+
EOF_KEY = "CTRL-Z" if sys.platform == "win32" else "CTRL-D"
7678

7779
def run_cli(self, *args, commands=()):
7880
with (
@@ -95,7 +97,7 @@ def run_cli(self, *args, commands=()):
9597
def test_interact(self):
9698
out, err = self.run_cli()
9799
self.assertIn(self.MEMORY_DB_MSG, err)
98-
self.assertIn(self.MEMORY_DB_MSG, err)
100+
self.assertIn(f'type ".quit" or {self.EOF_KEY} to quit', err)
99101
self.assertEndsWith(out, self.PS1)
100102
self.assertEqual(out.count(self.PS1), 1)
101103
self.assertEqual(out.count(self.PS2), 0)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correct the EOF key shown in the :mod:`sqlite3` CLI ``.help`` text on Windows.

0 commit comments

Comments
 (0)