I’m using titanium and testing against an android emulator – but any advice relevant to iOs is also welcome!
i am trying to use titanium with a database. I’m using the firefox sql lite plugin to make my db – so i make it, and then i go
database > export database > to a location in my titanium app project that is under "Resources" folder
ok, neat.
Then i have this code:
var db = Ti.Database.install('/db/wibbler.sql','wibbler');
function getLanguages(){
var sql = 'select * from language order by name desc';
var results = [];
var resultSet = db.execute(sql);
while (resultSet.isValidRow()){
results.push({
name: resultSet.fieldByName('name'),
id: resultSet.fieldByName('id'),
desctiption: resultSet.fieldByName('description')
});
reultSet.next();
}
resultSet.close();
return results;
}
As you can see, the location of the file is
Resources/db
and the db file is called “wibbler.sql”
The problem is, when i run my app, it complains that the sql i’m using refers to a table that doesn’t exist – to wit:
uncaught error: no such table
What is the deal?
Ok, so the answer is a bit of a mix – something from what Adam suggested, and some other stuff that i didn’t realise
First up: my file was just an exported sqllite database. That’s not right – the file should be the actual database file (so, you know, the “location” of the database that firefox makes should reside somewhere in the Resources folder, and titanium should point to that).
What cleared this up was this tutorial: http://blogs.usask.ca/the_bolt/archive/2010/12/titanium_tutorial_database.html
As noted in the tutorial, it is out of date – but all i needed to know was that I was using the wrong file in my titanium code.
Next, as Adam mentions, android will keep on using the old db – you can clean it out each time, but that is a hassle. Try this instead:
that finds the database, kills it, and the re-installs it. Also note that i’m now pointing to the sqlite file, not the sql file.
Hooray!