This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add an interactive shell for Sqlite3
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Big Stone, DiddiLeija, erlendaasland, r.david.murray, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-05-07 01:47 by rhettinger, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
sqlite3_repl.py rhettinger, 2018-05-07 01:46 Minimal proof-of-concept
0001-Add-proof-of-concept-REPL.patch erlendaasland, 2020-05-28 09:17
Messages (6)
msg316248 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-05-07 01:46
To facilitate rapid experimentation with SQL queries, add a shell to run commands and display results.

Attached is minimal proof-of-concept modeled loosely on the Linux sqlite3 REPL.  Here's a sample session:

    SQLite version 2.6.0

     Enter "help" for usage hints

    sqlite> open Irises.db
    sqlite> select distinct species from irises
    ('Iris-setosa',)
    ('Iris-versicolor',)
    ('Iris-virginica',)
    sqlite> select species, avg(pet_len), avg(sep_len) from irises group by species
    ('Iris-setosa', 1.464, 5.005999999999999)
    ('Iris-versicolor', 4.26, 5.936)
    ('Iris-virginica', 5.552, 6.587999999999998)
    sqlite> select count(*) from irises
    (150,)
    sqlite> quit
msg316257 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-05-07 10:52
It's not immediately obvious what benefits this provides over the existing sqlite-native repl and the python repl. Can you expand a bit on the use case?  Also, I seem to remember that Catherine Devlin had at one point thought about expanding her sqlpython to be multi-db capable, and while it doesn't look like that has happened, maybe that would be an alternative worth investigating?  (I've never used it or looked at its code, so it may not be.)
msg316261 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-07 11:07
It could be added in Tools/scripts directory or as a part of the sqlite3 module.

> It's not immediately obvious what benefits this provides over the existing sqlite-native repl and the python repl.

The existing sqlite-native repl is not always installed when Python is installed (especially on Windows). It is handy that Python provides CLI to some modules, including zipfile and tarfile.

I would prefer CLI, but maybe both interfaces can be combined.

It would be nice to provide also a graphical Sqlite3 browser, which can be ran as a separate application and be integrated with IDLE (as turtledemo).
msg327252 - (view) Author: Big Stone (Big Stone) Date: 2018-10-06 17:20
as a graphical sqlite browser, you have sqlite_bro that may give you inspiration. It's about one single file.
msg370180 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2020-05-28 09:17
I think this is a good idea. Proof-of-concept implementation added (invoke REPL with `python -m sqlite3`).

Possible improvements:
- Use sqlite3.complete_statement()
- Support Python syntax as well. For example:
>>> select * from t
>>> res = _
>>> print(res[0])
msg413072 - (view) Author: Diego Ramirez (DiddiLeija) Date: 2022-02-11 14:45
Do we still want to do this? See https://discuss.python.org/t/titling-sqlite3-table-columns-with-number/13656/3.
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77617
2022-02-11 14:45:10DiddiLeijasetnosy: + DiddiLeija

messages: + msg413072
versions: + Python 3.9, Python 3.10, Python 3.11
2020-05-28 09:17:47erlendaaslandsetfiles: + 0001-Add-proof-of-concept-REPL.patch

nosy: + erlendaasland
messages: + msg370180

keywords: + patch
2018-10-06 17:20:52Big Stonesetnosy: + Big Stone
messages: + msg327252
2018-05-07 11:07:36serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg316261
2018-05-07 10:52:21r.david.murraysetnosy: + r.david.murray
messages: + msg316257
2018-05-07 01:47:00rhettingercreate