sqlite3 .mode option to create HTML table automatically?

D

davidj411

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.

in fact, i found an old post saying 'if you want the output in a
table, you must create it yourself'.

Does anyone know if this is still the case?

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?

thanks!
David
 
R

Roger Binns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,514
Latest member
AdeleGelle

Latest Threads

Top