sqlite3 .mode option to create HTML table automatically?

Roger Binns rogerb at rogerbinns.com
Thu Dec 24 23:40:40 EST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

davidj411 wrote:
> the CLI for sqlite3 shows .mode of "html", which formats the output in
> HTML format that is good to add to <TABLE>.
> 
> BUT i have not yet found anything for sqlite in python that does this.

The CLI is extra code (in C) that wraps the SQLite library and adds
functionality like this.  You can call the CLI from your Python code (use
the subprocess module) and capture output that way.

Alternatively you can use APSW (disclosure: I am the author of APSW).  APSW
comes with a shell modelled on the SQLite one:

  http://apsw.googlecode.com/svn/publish/shell.html

The Shell is written in Python (see Shell class lower in that page for API
information).  You can instantiate one with stdout set to a StringIO and
then give it commands by calling shell.process_complete_line.

You can also embed the Shell in your program, add commands and output modes etc.

> also, i'd like to know if i can get headers in the result set.
> The CLI uses '.header ON' to enable this.
> is there a place where i can change this too?

The APSW shell supports that.  The APSW home page is at:

  http://code.google.com/p/apsw/

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAks0QkIACgkQmOOfHg372QS9UgCeJh+QEx61AKK2+7XBFZ0hjIOu
FtYAoKJdjlitJuFmix0DGq7hojqKTIpN
=kRhG
-----END PGP SIGNATURE-----




More information about the Python-list mailing list