[Python-ideas] interactive sqlite3 module
ZeD
zak.mc.kraken at libero.it
Tue Jun 25 14:33:50 CEST 2013
Hi.
some python modules contains a "console" usage (for example the module timeit).
It would be useful (for the times when you have python installed but not a
sqlite executable... think windows...) to add a minimal interactive sqlite
interpreter... a (really) basic implementation is something like the source
below... teoretically the idea is to to
$ python -msqlite3 'my_data.db'
or
$ python -msqlite3 ':memory:'
and have a simple sqlite interpreter
do you think it whould be useful?
-------------------------
#!/usr/bin/env python
# ATM I'm on python2...
from __future__ import print_function
try:
input = raw_input
except:
pass
# ideally this file is part of sqlite
from sqlite3 import *
def main():
from sys import argv
if len(argv) < 2:
raise SystemExit("usage: %s DATABASE" % (argv[0], ))
with connect(argv[1]) as conn:
while True:
command = input("> ")
if command == '.exit':
break
try:
c = conn.cursor()
for row in c.execute(command):
print(row)
conn.commit()
except Exception as e:
print(e)
if __name__ == '__main__':
main()
--
Vito 'ZeD' De Tullio
More information about the Python-ideas
mailing list