Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Lib/sqlite3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
from textwrap import dedent


# IDLE uses CTRL-D for EOF on all platforms (gh-102628).
if sys.platform == "win32" and "idlelib.run" not in sys.modules:
EOF_KEY = "CTRL-Z"
else:
EOF_KEY = "CTRL-D"


def execute(c, sql, suppress_errors=True):
"""Helper that wraps execution of SQL code.

Expand Down Expand Up @@ -102,16 +109,12 @@ def main(*args):
db_name = repr(args.filename)

# Prepare REPL banner and prompts.
if sys.platform == "win32" and "idlelib.run" not in sys.modules:
eofkey = "CTRL-Z"
else:
eofkey = "CTRL-D"
banner = dedent(f"""
sqlite3 shell, running on SQLite version {sqlite3.sqlite_version}
Connected to {db_name}

Each command will be run using execute() on the cursor.
Type ".help" for more information; type ".quit" or {eofkey} to quit.
Type ".help" for more information; type ".quit" or {EOF_KEY} to quit.
""").strip()
sys.ps1 = "sqlite> "
sys.ps2 = " ... "
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_sqlite3/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""sqlite3 CLI tests."""
import sqlite3
import sys
import unittest

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

def run_cli(self, *args, commands=()):
with (
Expand All @@ -95,7 +97,7 @@ def run_cli(self, *args, commands=()):
def test_interact(self):
out, err = self.run_cli()
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(f'type ".quit" or {self.EOF_KEY} to quit', err)
self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 0)
Expand Down
Loading