Hi,

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?

Thanks,
Tom



Well, you didn't say which midware or platform were you using. I'll talk in the perspective of C API.

In reality, we never parse query results directly from the "table" output from command line shell. I think, usually, the command line shell is provided for the convenience of quickly evaluating some of the details of the database system. But when you were to develop an application, you simply don't use the database through a command line shell.

You are supposed to use a combination of sqlite3_open, sqlite3_prepare, sqlite3_step, which are the APIs provided by sqlite, to access the database. And use APIs like sqlite3_column_* to get the content of the query. It certainly doesn't matter if there are return characters in the results. It won't matter even if characters are unreadable binaries. That's why we have a BLOB type. You are not supposed to parse them, you can get them directly through these APIs. You might want to learn more about a database management system, after all, sqlite is one.

Best regards,
He Shiming

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to