Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to test persistent storage?

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?

— asked March 30th 2010 by Zach Copley
  • database
  • sqlite
  • storage
0 Comments

5 Answers

  • 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");
    
    — answered April 5th 2010 by Zach Copley
    permalink
    0 Comments
  • 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);
    
    — answered March 30th 2010 by Zach Copley
    permalink
    0 Comments
  • I've the same problem here.

    Doing also:

    var separator = Titanium.Filesystem.getSeparator();
    var dbFile = Titanium.Filesystem.getFile(Titanium.Filesystem.getResourcesDirectory() + separator + "mydb.db");
    this.db = Titanium.Database.openFile(dbFile);

    Then:

    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.

    Chris,

    TESTING on Desktop platforms: WIN & MAC

    — answered April 2nd 2010 by Christophe Bonnarens
    permalink
    0 Comments
  • what platform are you testing on?

    — answered March 30th 2010 by Don Thorp
    permalink
    0 Comments
  • Ok …

    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 ?

    Thanks,

    Chris,

    — answered April 3rd 2010 by Christophe Bonnarens
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.