【问题标题】:when does executing() return false in sqlite for flex?什么时候execution()在sqlite中为flex返回false?
【发布时间】:2010-11-26 08:12:15
【问题描述】:

我已阅读 flex 语言参考: http://livedocs.adobe.com/flex/3/langref/flash/data/SQLStatement.html#executing

如果调用了 execute() 并且并非所有结果都已从数据库返回,则此属性为真。

但是,我无法理解这到底是什么意思。我不断收到错误消息:

错误 #3106:当 SQLStatement.executing 为 true 时,无法更改属性。

我尝试为 SQLEvent.RESULT 创建一个事件处理程序,我的想法是这就是从数据库返回结果的方式,因此 execution() 将返回 false - 不起作用。

这是否意味着我试图太快地更改我的 SQLStatement 变量? execute() 函数需要多长时间?

有问题的代码:

private function fileProgress(p_evt:ProgressEvent):void {
            var char:String;
            var line:String = "";
            var counter:int = 1;

            sqlStatement = new SQLStatement();
            sqlStatement.sqlConnection = dbConn;
            while(stream.position < stream.bytesAvailable) 
            {
                char = stream.readMultiByte(1, File.systemCharset);
                if(char == "\n")
                {
                    sqlStatement.text = "INSERT INTO stats VALUES ('" + counter + "','" + line + "');";
                    sqlStatement.execute();
                    counter++;
                    line = "";
                }
                else
                {
                    line += char;
                }
                readProgress.text = ((p_evt.bytesLoaded/1048576).toFixed(2)) + "MB out of " + ((p_evt.bytesTotal/1048576).toFixed(2)) + "MB read";
            }

            if(line != "")
            {
                sqlStatement.text = "INSERT INTO stats VALUES ('" + line + "');";
                sqlStatement.execute();
            }

        }

stream 是一个文件流
我正在尝试读取一个文本文件并将每一行放入一个新的 sqlite 表行中。
我也尝试使用 sqlStatement.parameters 作为插入查询的替代方法,但没有运气。引发不同的错误:

错误 #3110:当 SQLStatement.executing 为真时无法执行操作。

【问题讨论】:

    标签: apache-flex sqlite air


    【解决方案1】:

    最好为每个查询创建一个新的 SQLStatment,而不是重复使用 SqlStatement。
    它也应该在 OpenAsyn 模式下工作。

    var statement:SQLStatement; 
    for(..) //LOOP
    {
                statement =new SQLStatement();
                statement.sqlConnection = dbConn;
                statement.text="QUERY HERE";
                statement.execute();
    }
    

    【讨论】:

      【解决方案2】:

      试试cancel()

      【讨论】:

      • 刚刚试了一下,没用。但我很高兴,因为我不想取消 sqlstatement.execute()。我希望它每次都在被解雇之前完成
      【解决方案3】:

      如果有人来看这里,我想我会发布我的解决方案。

      只需将 SQL 连接从 connection.openAsync() 更改为 connection.open()

      这为我消除了错误

      【讨论】:

      • 您所做的是将异步模式更改为非异步模式。虽然这对于您希望在使用大型数据库时保持异步的小型应用程序来说是可以的。
      【解决方案4】:

      当调用 execute() 或 execute(-1) --> execution() 立即返回 false(如果在同步模式下)或在 SQLResult 事件触发后(如果在异步模式下)。

      当使用预取 > 0 调用 execute() 时,execute() 仅在返回整个结果集时才返回 false。例如 execute(10) 将返回最多 10 行。如果 execution() 为真,则意味着有更多数据,您需要调用 next() 来获取接下来的 10 行。继续调用 Next() 直到 execution() 为假。您可以随时调用 cancel() 提前退出(例如,如果您只想要前 10 行。)

      【讨论】:

        猜你喜欢
        • 2016-09-05
        • 1970-01-01
        • 1970-01-01
        • 2012-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多