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 access an SQLite Database from a desktop application.

I've been using:

'adp = Titanium.API.Application.getDataPath();
dbpath = adp + "test.sql";
var db = Titanium.Database.openFile(dbpath);

var resultSet = db.execute("SELECT * FROM test_table");
if (resultSet.isValidRow()) { Titanium.API.info('OK'); }'

But I always get the following error message:

'SQL Statement invalid or database missing'

Is there something wrong with the code, or the database I had created?

— asked May 4th 2010 by Leonard Charles
  • database
  • desktop
  • error
  • lite
  • sql
0 Comments

5 Answers

  • "if you log adp to the console, is it going to where the db is?"

    Interestingly, it logs (in Vista):

    C:/User/'Username'/AppData/Roaming/Titanium/appdata/tbooktest.sql

    Which is a problem, because I expect to find a '/' between the end of the word 'tbook' and the start of the word 'test'.

    Thing is, I don't know where the DB is supposed to be at run time.
    My guess is:

    C:/User/'Username'/AppData/Roaming/Titanium/appdata/tbook/test.sql

    Which I've tried. But I only get the following message:

    'Cannot open database file'

    'test.sql' is found in the resources directory.
    I thought it would be possible to use this line?:

    Titanium.Database.open('test.sql')

    which leads to:

    SQL Statement invalid or database missing
    [20:14:54:634] [Titanium.Database.DB] [Error] Exception executing: SELECT * FROM test_table, Error was: SQL Statement invalid or database missing

    This is why I wonder if there's a problem with the DB itself.
    TBH, I may just dump the idea of using a database for the desktop app… The design could benefit from the decision, but I'm keen on getting this to work.

    What's the simplest way to access a ready made sqlite database, using the Titanium API?

    — answered May 5th 2010 by Leonard Charles
    permalink
    0 Comments
  • if you log adp to the console, is it going to where the db is?

    — answered May 4th 2010 by Clint Tredway
    permalink
    0 Comments
  • Duplicate post!

    — answered May 5th 2010 by Leonard Charles
    permalink
    0 Comments
  • var adp=Titanium.API.Application.getDataPath();
    var dbpath = adp+"\"+"data.db";
    var db = Titanium.Database.openFile(dbpath);
    var rows = db.execute('INSERT INTO users (userName, firstName, lastName) VALUES("'+txt1.value+'","'+txt2.value+'", "'+txt3.value+'")');
    var rs = db.execute("select * from users");
    while(rs.isValidRow())
    {
    rs.next();
    }
    alert('Inserted Value is: ' + rs.fieldByName('firstName') + ' : ' + rs.fieldByName('lastName')+ 'With User Name :' +rs.fieldByName('userName'));

    Try this…

    — answered June 14th 2010 by Varun Atluri
    permalink
    0 Comments
  • Hi all, friend now i am interesting Titanium desktop application… Any one help me how to save database create code(i mean file name) and how to access

    — answered September 26th 2011 by Rajamurugan A
    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.