1

I'm new to TideSDK so I am doing some tests. I found that the API has some methods to manage and retrieve data stored in a local DB. I created a table named Users with only two fields, id and name (This is the example at http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Database.DB), which I have fill with some random numbers and names. This is the function I am using:

function consulta (){
//Open the database first
var db = Ti.Database.openFile(Ti.Filesystem.getFile(
                          Ti.Filesystem.getApplicationDataDirectory(),    'customdatabase.db'));   

var rows = db.execute("SELECT * FROM Users ORDER BY firstName");

while (rows.isValidRow()) {

    document.getElementById('resultado').innerHTML = 'The user id is '+rows.fieldByName('id')+', and user name is '+rows.fieldByName('firstName')+'<br>';
rows.next();    
}
 document.getElementById('filas').innerHTML = rows.rowCount( );
//Release memory once you are done with the resultset and the database
rows.close();
db.close();
 }** 

My problem is this: Though the result of method rowCounts() is 29 (Meaning, of course, that there are 29 rows in the result), the WHILE block is just out puting one single row instead. Can someone help me to make this work? Shouldn't I use the API for this?

2 Answers2

1

Checkout Sample API Usage for Database module here.

Mital Vora
  • 2,199
  • 16
  • 19
1

Try this:

while (rows.isValidRow()) {

document.write('The user id is '+rows.fieldByName('id')+', and user name is '+rows.fieldByName('firstName')+'<br >'); rows.next(); } document.getElementById('filas').in nerHTML = rows.rowCount( ); //Release memory once you are done with the resultset and the database rows.close(); db.close(); }

Place the script inside the body

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
chris
  • 11
  • 1