Not sure what I'm missing - display data from database
Hi,
not sure what I'm missing here. I'm using code from the kitchen sink. I'm just trying to display the data that was inserted into the db. I don't get any errors when it's compiling the code. It just won't display any data.
thanks for any help!
var db = Titanium.Database.open('mydbdd');
db.execute('DROP TABLE IF EXISTS DATABASETEST');
db.execute('CREATE TABLE IF NOT EXISTS DATABASETEST (ID INTEGER, NAME TEXT)');
db.execute('INSERT INTO DATABASETEST (ID, NAME) VALUES(?,?)',1,'name one');
db.execute('INSERT INTO DATABASETEST (ID, NAME) VALUES(?,?)',2,'name two');
db.execute('INSERT INTO DATABASETEST (ID, NAME) VALUES(?,?)',3,'name three');
Titanium.API.info('JUST INSERTED, rowsAffected = ' + db.rowsAffected);
Titanium.API.info('JUST INSERTED, lastInsertRowId = ' + db.lastInsertRowId);
var rows = db.execute('SELECT * FROM DATABASETEST');
Titanium.API.info('ROW COUNT = ' + rows.getRowCount());
while (rows.isValidRow())
{
Titanium.API.info('ID: ' + rows.field(0) + ' NAME: ' + rows.fieldByName('name'));
rows.next();
}
rows.close();
Titanium.UI.currentWindow.close();
3 Answers
-
Wrap your code in a try/except clause or switch on trace level debugging if you're on Android to find out what the problem is.
-
Hi Damien,
Thanks for the help. This is for the iphone. I'm not receiving any errors when it compiles to the simulator. It just seems as if it's not writing the results to the page.
-
info logs to output of Ti Developer, not a webpage, in case that's not clear. If you're not seeing anything appearing in Ti Developer, add some debug statements to see where things are progressing to before failing.