无法使用TideSDK API从查询结果中获取所有行

时间:2013-08-24 17:43:01

标签: database sqlite resultset tidesdk

我是TideSDK的新手所以我正在做一些测试。我发现API有一些方法来管理和检索存储在本地数据库中的数据。我创建了一个名为Users的表,只有两个字段,id和name(这是http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Database.DB的示例),我填写了一些随机数字和名称。这是我正在使用的功能:

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

我的问题是:虽然方法rowCounts()的结果是29(当然,意思是结果中有29行),WHILE块只是放置一行而不是。有人可以帮助我做这项工作吗?我不应该为此使用API​​吗?

2 个答案:

答案 0 :(得分:1)

结帐数据库模块here的示例API使用情况。

答案 1 :(得分:1)

试试这个:

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

将脚本放在正文中

相关问题