Skip to content

Instantly share code, notes, and snippets.

@bmadigan
Created June 28, 2010 15:59
Show Gist options
  • Save bmadigan/456006 to your computer and use it in GitHub Desktop.
Save bmadigan/456006 to your computer and use it in GitHub Desktop.
try {
var adp = Titanium.API.Application.getDataPath();
var dbpath = adp+"\\"+"sampledb.db";
var db = Titanium.Database.openFile(dbpath);
//var db = Titanium.Database.open('recruitment'); // this doesn't work either
}
catch (e) {
alert(e); // seems to connect as this doesn't come up
}
// select
var result = db.execute('SELECT firstname, lastname FROM users');
// Create an array
var rs = [];
var j = 0;
try {
while (result.isValidRow())
{
rs[j][firstname] = result.fieldByName('firstname');
rs[j][lastname] = result.fieldByName('lastname');
j++;
result.next();
}
} catch(e) {
alert('Note: You have not entered any valid Users yet.'); // THIS IS ALWAYS CALLED
}
// close result set
result.close();
db.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment