【问题标题】:Can't get all rows from a query result using TideSDK API无法使用 TideSDK API 从查询结果中获取所有行
【发布时间】:2013-08-27 14:24:06
【问题描述】:

我是 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 吗?

【问题讨论】:

    标签: database sqlite resultset tidesdk


    【解决方案1】:

    查看数据库模块 here 的示例 API 用法。

    【讨论】:

      【解决方案2】:

      试试这个:

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

      将脚本放在正文中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-19
        • 1970-01-01
        • 2018-07-12
        • 2021-07-23
        • 2013-12-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多