Exporting data from SQLite
I recently discovered that sqlite3 has a number of output modes to spit out query results in different formats:
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elementsBy specifying .mode insert one can get nicely formatted insert statements that can be imported right into MySQL. This is what I did to convert my Voicemail app to MySQL. However, if you don’t specify a table name on the same line, the resulting insert statements just say “insert into table”. One must use .mode insert voicemails to get insert statements out of sqlite3 that read “insert into voicemails”. A bit silly if you ask me… one would think the table name in the insert statements would just default to the name of the table you were selecting from. But, this worked great for me and was all I needed to get converted.
