Reputation: 868
So, for some reason, I am having a bit of trouble with my sqlite database. I'm trying to dump my database into a file that could be used in Titanium. I know about the .dump
command, but when I try to use the instructions on the sqlite website:
A good way to make an archival copy of a database is this:
$ echo '.dump' | sqlite3 ex1 | gzip -c >ex1.dump.gz
and change the ex1.dump.gz
to ex1.sqlite.gz
, it gives a really messed up file that is useless. How can I dump my database so that I can then use it in my Titanium Studios mobile app?
Upvotes: 0
Views: 510
Reputation: 74909
.dump
exports the contents of your database as a series of insert statements. If you run it without the gzip
command you'll see plain text sql:
$ echo '.dump' | sqlite3 ex1
But you don't need to do that to use a SQLite database in Titanium Studios. It supports SQLite natively. Just copy the database file to your project directory and then use code like this to open it:
var db = Ti.Database.install('../products.sqlite','products');
var rows = db.execute('SELECT DISTINCT category FROM products');
More details here:
Upvotes: 1
Reputation:
Why do you dump the database file when you can simply copy it, i.e. use it as it is?
As explained here, sqlite databases are cross-platform:
A database in SQLite is a single disk file. Furthermore, the file format is cross-platform. A database that is created on one machine can be copied and used on a different machine with a different architecture. SQLite databases are portable across 32-bit and 64-bit machines and between big-endian and little-endian architectures.
On the other hand, you should be able to dump, compress you database like this:
echo '.dump' | sqlite3 foo.db | gzip -c > foo.dump.gz
and restore it in a new SQLite database:
gunzip -c foo.dump.gz | sqlite3 foo.new.db
Upvotes: 1