使用 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 对象,但它的数据为空.
Checking the program during runtime gives me that sqls.getResult() returns a valid SQLResult object, but its data is null.
从我之前的问题 Adobe 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.
尽管如此,我已经用
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 变为空的可能原因是什么?
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 为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!