I have been trying to install a tiny simple database into my titanium project with the code from the documentation and trying different tweaks as suggested by a variety of sources. But I cannot get it to work, I get errors like "no such table" or resultset is null. Currenty my code looks like this:
var db = Ti.Database.install('../assets/exercises.db', 'exercisesDB');
Ti.API.info('installed '+ db.getName() );
db.close();
Ti.API.info('closed db' );
db = Ti.Database.open('exercisesDB');
Ti.API.info('reopened db' );
//Ti.API.info(db.getName() );
var exercisesDBRS = db.execute('SELECT id,name FROM exercise');
I have tried putting the database file exercises.db in the assets folder and in the Resources folder but I'm getting no where. I created the db file with "DB Browser for SQLite" ver 3.9.1 on OSX Sierra - is it compatible with appcelerator alloy projects? My current code produces the error "no such table" on the execute call. I assure you the db file has an exercise table.
PS, full code in new projects index.js file is as follow:
var db = Ti.Database.install('exercises.sqlite', 'exercisesDB');
Ti.API.debug('installed '+ db.getName() );
db.close();
Ti.API.debug('closed db' );
db = Ti.Database.open('exercisesDB');
Ti.API.debug('reopened db' );
var exercisesDBRS = db.execute('SELECT id, name FROM exercise');
Ti.API.debug('executed select');
Ti.API.debug(' rowcount== '+ exercisesDBRS.rowCount);
while (exercisesDBRS.isValidRow()) {
var exId = exercisesDBRS.fieldByName('id');
var exName = exercisesDBRS.fieldByName('name');
Ti.API.debug("Exercise: "+exId + ' ' + exName );
exercisesDBRS.next();
}
exercisesDBRS.close();
db.close();
function doClick(e) {
alert($.label.text);
}
$.index.open();
New project but same code and a copy of the same database file in the app/lib folder. Same error - no such table on the execute line when tested in android, works fine in iOS sim.