Sqlite3 pretty output
#################

Lets make pretty sqlite output, or else it will look like below unpretty.

NOTE: here pretty means, how cool something looks and how easy it is to read

NOTE: below column examples are missing tabs that the actual output has, just pretend they are there

Pretty just means to add header row (followed by the dashed pretty seperator line). And also to tab out columns.

I show 2 ways to do each command (with and without an echo&pipe).
NOTE: we use this file for example /var/db/smart.sq3 (numbers have been changed to remove identity)


UNPRETTY:
=========

Here is the output for both commands (notice its hard to read, and not that pretty)


 

PRETTY:
=======

Method 1  (-header and -cmd ‘.mode columns’)

Use -header  for headers and -cmd '.mode columns'  for columns

The output is:

Method 2 (echo everything)

We will echo in the following thing into sqlite (the sqlite file will have 1 argument which will pointed at the database)

Here is the echo piped to sqlite for the pretty end result

Method 3 (-header and -column)

Instead of saying “.header on” you can just put “-header” argument

 Method 4 (-header and -column and -cmd ‘.width NUM1 NUM@’)

Adjust widths as well

More info on width (it just sets how many chars wide each column is, and it will trim out chars if you pick a small number. we size the columns from left to right. it automatically sizes the columns you dont mention)

Here is another example. Here is output without changing widths

Output without widths:

Now lets change the width of ID to 3 (since drive letters are only 3 chars big), lets change VOLUME to 6 (since the biggest volume name has 6 chars), lets change the next column which is CHANNEL to 2 (because the values are 1 digit, and I want the column header to appear as CH which makes senses and has close resemblance to the word CHANNEL, setting it to 1 would be enough except the column header would only say C).

Output with widths 3 and 6 and 2:

NOTE: notice how the remaining columns are sized automatically by sqlite3, and with the width command we size the columns from left to right.

More options on Pretty output 

All of this is from the man page of sqlite3

From this page: http://www.sqlite.org/cli.html

 

Leave a Reply

Your email address will not be published. Required fields are marked *