Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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();

— asked May 31st 2010 by Dave Devitt
  • database
  • iphone
0 Comments

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.

    — answered May 31st 2010 by Damien Elmes
    permalink
    0 Comments
  • 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.

    — answered May 31st 2010 by Dave Devitt
    permalink
    2 Comments
    • i don't see in the code above (bad paste by the way, either use formatting syntax or a pastie link) where you're doing anything except logging output.

      — commented May 31st 2010 by Jeff Haynie
    • Hi Jeff…thanks. That's my problem. I'm not sure how to spit it out. I know I need to use database.resultset but I'm unclear how to. Can you help?

      — commented May 31st 2010 by Dave Devitt
  • 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.

    — answered May 31st 2010 by Damien Elmes
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.