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?
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 missingThis 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?
-
if you log adp to the console, is it going to where the db is?
-
Duplicate post!
-
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…
-
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