I seem to be able to do inserts, but the rows don't seem to stick around. The next time I launch the app via Titanium desktop, I can't find them. And there's nothing in the database file – I have checked using some other tools for reading sqlite3 databases. I suspect that a brand new database is getting created each time I launch my app as part of the build process.
How am I supposed to test that my app can save stuff permanently to a database file?
Okay, I figured it out (with the help of a coworker who's better at reading the API documentation, apparently). The database file needs to be opened in the application's data directory, otherwise it will get overwritten every time you build. Instead of .getResourcesDirectory(), use .getApplicationDataDirectory().
Titanium.Filesystem.getApplicationDataDirectory: Return the data directory of the application. The data directory is per-user directory for storing application data. It is guaranteed to be writable and stable between releases.
var dbFile = Titanium.Filesystem.getFile(Titanium.Filesystem.getApplicationDataDirectory() + separator + "mydb.db");
I'm writing a Desktop app (1.0.0 SDK). Testing on Mac and Linux.
My code to open the file looks like this:
var separator = Titanium.Filesystem.getSeparator(); var dbFile = Titanium.Filesystem.getFile(Titanium.Filesystem.getResourcesDirectory() + separator + "mydb.db"); this.db = Titanium.Database.openFile(dbFile);
I've the same problem here.
var separator = Titanium.Filesystem.getSeparator();
var dbFile = Titanium.Filesystem.getFile(Titanium.Filesystem.getResourcesDirectory() + separator + "mydb.db");
this.db = Titanium.Database.openFile(dbFile);
var changeit = db.execute('UPDATE config SET lang="fr" WHERE lang="en"');
The command is executing and I've no result in the db file !
SQL Returned 0 rows …
I do the same execute command in sqlite Manager and it's working fine.
I can do SELECT without any problems but INSERT and UPDATE aren't working !
I'm going crazy.
Thank you if someone has an explanation.
TESTING on Desktop platforms: WIN & MAC
what platform are you testing on?
I packaged my app and the update query is working ??
So it's working after packaging but not working in dev environnement (in Titanium developper test).
How can I arrange this ?