在标签中传递SQL结果

时间:2012-09-04 09:44:26

标签: actionscript-3 sqlite air

我有一个选择语句,可以查询获得高分的前5名球员

selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;            
selectStmt.text="SELECT name, level, score FROM highscores WHERE ROWID <=5 ORDER BY score DESC";        
selectStmt.execute();

我希望标签中显示的名称,级别和分数。如何在标签中传递结果?

1 个答案:

答案 0 :(得分:0)

你必须:

  1. 倾听SQLEvent.RESULT
  2. 执行您的查询
  3. 处理结果
  4. selectStmt = new SQLStatement();
    selectStmt.sqlConnection = conn;
    selectStmt.text="SELECT name, level, score FROM highscores WHERE ROWID <=5 ORDER BY score DESC";
    
    // Create a listener in order to process the results
    var resultHandler:Function = function(event:SQLEvent):void {
        selectStmt.removeEventListener(SQLEvent.RESULT, resultHandler);
    
        // Get the result
        var result:SQLResult = dbStatement.getResult();
        if (result != null) {
            // Iterate through each entries
            for each (var entry:Object in result.data) {
                // Trace entry
                trace(entry.name, entry.level, entry.score);
            }
        }
    };
    
    // Add a listener in order to read the results when the request will be done
    selectStmt.addEventListener(SQLEvent.RESULT, resultHandler);
    selectStmt.execute();