Following up my earlier post:
I have a database where some values contain carriage returns. I am
using the command line to execute sqlite commands, eg:
sqlite3 Disney.db "SELECT * FROM Characters"
When I get the result of a SELECT statement, the output has columns
separated by pipe characters and rows by new lines. So, if a value
contains a return, it prematurely starts a new line, and messes up
my output result.
What's the best approach to deal with this?
I guess I could use the command:
.mode csv
to change the output to csv (which wraps newlines in values within
quotes). But it doesn't hold from one sqlite3 command to the next.
And I can't see how to do this in a single command line, and
there'd be too much overhead to write the ".mode" and SELECT
commands to a temporary file to then invoke through a sqlite3 command.
I hope I'm missing something simple. Can anyone help, please?
On the man page for sqlite3, it gives command line options to
activate html or line output mode, by:
sqlite3 -line
sqlite3 -html
but there doesn't appear to be an equivalent option to format the
output as csv, ie:
sqlite3 -csv
And CSV seems to be the only output that encapsulates carriage returns.
I finally figured that I can do it using a pipe, eg:
echo ".mode csv
SELECT * FROM Characters;" | sqlite3 Disney.db
If anyone has a neater solution, please let me know. But for now this
achieves my requirement of capturing carriage returns in the output
values.
Thanks,
Tom
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------