Titanium Community Questions & Answer Archive

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

Cannot open database file

I'm trying to connect to an SQLite database, but I can't get it working. I tried to calling openFile on a nonexisting file hoping it will create one. I then create a db file with Firefox's SQLite Manager and then tried to open with openFile, but i get the "Cannot open database file".

Here's the code: http://www.pastie.org/1011928

— asked June 19th 2010 by Rok Carl
  • database
  • desktop
  • sqlite

2 Answers

  • Accepted Answer

    var db = Titanium.Database.openFile(Titanium.API.application.dataPath, "baza.sqlite");

    replace above code with the following:

    var db = Titanium.Database.openFile(Titanium.API.application.dataPath, "\baza.sqlite");

    check weather the path is correct or not by doing the following:

    var adp=Titanium.API.Application.getDataPath();
    alert(adp);// here u should get base path;
    var dbpath = adp+"\data.db";
    alert(dbpath);// here u should get total path by concatenating data.db;
    var db = Titanium.Database.openFile(dbpath);

    — answered June 21st 2010 by Varun Atluri
  • If you have a database that exists / ships with your app then use Database.install() like:

    //Open/install the database
    var db = Titanium.Database.install('../existingdb.db', 'myDatabase');

    You can call that multiple times as install will only occur once.

    Creating a new database use Database.open :

    var db = Titanium.Database.open('todos');
    db.execute('CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, todo TEXT)');

    Check the persistance example app as it has working examples.

    — answered June 20th 2010 by James Whittaker
    1 Comment
    • This example seems to be for Titanium Mobile, while the question was related to Titanium Desktop.

      — commented July 4th 2011 by Richard Lustemberg
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.