Adobe Air:为什么SQLStatement的getResult().data为null? [英] Adobe Air: why SQLStatement's getResult().data is null?

查看:139
本文介绍了Adobe Air:为什么SQLStatement的getResult().data为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Flash Builder 4.6,我正在关注 http://以www.flex-blog.com/adobe-air-sqlite-example (链接似乎已断开)为例,其中有一部分代码那不起作用:

Using Flash Builder 4.6, I am following http://www.flex-blog.com/adobe-air-sqlite-example (edit: link seems to be broken) as an example, and there is one part of codes that does not work:

private function resault(e:SQLEvent):void
{
    // with sqls.getResault().data we get the array of objects for each row out of our database
    var data:Array = sqls.getResult().data;
    // we pass the array of objects to our data provider to fill the datagrid
    dp = new ArrayCollection(data);
}

在运行时检查程序可以使我sqls.getResult()返回有效的SQLResult对象,但其数据为null.

Checking the program during runtime gives me that sqls.getResult() returns a valid SQLResult object, but its data is null.

从我之前的问题 Adob​​e Air:将sqlite的结果[object Object]转换为String?,看来我是问一个错误的问题.

And from my previous question Adobe Air: convert sqlite's result [object Object] to String?, it seems I am asking the wrong question.

尽管如此,我还是用

检查了我的SQLResult对象.

Nevertheless, I've checked my SQLResult object with

trace(ObjectUtil.toString(sqls.getResult()));

我可以看到我从sqlite获取了所有内容:

and I can see that I got all of my content from sqlite:

(flash.data::SQLResult)#0
  complete = true
  data = (Array)#1
    [0] (Object)#2
      first_name = "AAA"
      id = 1
      last_name = "BBB"
    [1] (Object)#3
      first_name = "AAA"
      id = 2
      last_name = "BBB"
    [2] (Object)#4
      first_name = "qqq"
      id = 3
      last_name = "qqq"
  lastInsertRowID = 0
  rowsAffected = 0

那么这是怎么回事?我真的必须创建自己的函数来解析所有sqlite元素,然后将其自己放置在数据提供程序中吗?是的,我可以这样做,但是说真的,很多教程都显示了使用:

So what's going on here? Do I really have to create my own function to parse all of my sqlite elements and then place them in the data provider myself? Yes, I can do that, but seriously, many tutorials have shown using:

var data:Array = sqls.getResult().data;
dp = new ArrayCollection(data);

现在,回到问题所在:sqls.getResult().data可能为null的可能原因是什么?

Now, back on the question: What might be the possible causes of sqls.getResult().data becoming null?

推荐答案

在我看来,这并不是一个很好的教程.在该代码中,您为所有正在执行的语句提供了一个事件侦听器.它甚至只有一个执行不同查询的SQLStatement.我不知道您的代码到底出了什么问题,但是我可以确定原因在那儿. (并且甚至不让我开始使用该Timer作为语句仍在执行时的延迟.糟糕!).我强烈建议您寻找学习Flex/AIR/SQLite的更好资源.

That doesn't look like a very good tutorial you're following there (in my opinion). In that code, you have one event listener for all the statements that are being executed. It even has just one SQLStatement that executes different queries. I don't know exactly what is going wrong with your code, but I'm fairly certain the cause is to be found there. (And don't even get me started about that Timer used as a delay when a statement is still executing. Yuck!). I strongly suggest you look for a better source for learning Flex/AIR/SQLite.

您应该仅创建一个新的SQLStatement,或者至少为每个Statement执行创建离散事件处理程序.更好的方法是使用 Responder 类,如下所示:

You should simply create a new SQLStatement, or at least discrete event handlers for each Statement execution. A better way to do this, would be to use the Responder class, like this:

var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = connection;
stmt.text = query;

var token:Responder = new Responder(onResult, onFail);
stmt.execute(-1, token);

但是,如果您不介意一直保持与数据库的连接一直打开,则可以共享SQLConnection.

The SQLConnection can be shared though, if you don't mind keeping the connection to your database open all the time.

这篇关于Adobe Air:为什么SQLStatement的getResult().data为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆