mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.11] gh-95273: Improve sqlite3.complete_statement docs (GH-95840) (#95917)
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>.
(cherry picked from commit e6623e7083
)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
parent
577dbc3c49
commit
bd86e09ab9
2 changed files with 14 additions and 39 deletions
|
@ -1,33 +0,0 @@
|
|||
# A minimal SQLite shell for experiments
|
||||
|
||||
import sqlite3
|
||||
|
||||
con = sqlite3.connect(":memory:")
|
||||
con.isolation_level = None
|
||||
cur = con.cursor()
|
||||
|
||||
buffer = ""
|
||||
|
||||
print("Enter your SQL commands to execute in sqlite3.")
|
||||
print("Enter a blank line to exit.")
|
||||
|
||||
while True:
|
||||
line = input()
|
||||
if line == "":
|
||||
break
|
||||
buffer += line
|
||||
if sqlite3.complete_statement(buffer):
|
||||
try:
|
||||
buffer = buffer.strip()
|
||||
cur.execute(buffer)
|
||||
|
||||
if buffer.lstrip().upper().startswith("SELECT"):
|
||||
print(cur.fetchall())
|
||||
except sqlite3.Error as e:
|
||||
err_msg = str(e)
|
||||
err_code = e.sqlite_errorcode
|
||||
err_name = e.sqlite_errorname
|
||||
print(f"{err_name} ({err_code}): {err_msg}")
|
||||
buffer = ""
|
||||
|
||||
con.close()
|
Loading…
Add table
Add a link
Reference in a new issue