Grimoire-
Command
.es

GNU+Linux command memo

Improvise an SQLite command line interface in Python

Improviser un client SQLite via la bibliothèque de fonction Python

Sometime, it feels easier to make a short alias instead of starting to search for the good Debian based package of the official client program and its own syntax…

Usage :

$ sqlyte3 <database.sqlite3> '<plain SQL request>'

Convenient shell alias to copy :

$ alias sqlyte3='python -c"import sqlite3,sys,pprint;a=sqlite3.connect(sys.argv[1]);b=a.cursor();pprint.pprint(b.execute(sys.argv[2]).fetchall())"'

Unpacked Python code :

import sqlite3,sys,pprint

a = sqlite3.connect(sys.argv[1])
b = a.cursor()
pprint.pprint(b.execute(sys.argv[2]).fetchall())