2009-09-07 53 views
0

我读过柔性语言参考: http://livedocs.adobe.com/flex/3/langref/flash/data/SQLStatement.html#executing什么时候执行()返回错误在sqlite为flex?

This property is true if execute() has been called and not all of the results have been returned from the database.

不过,我无法理解这意味着什么究竟。我不断收到一个错误:

Error #3106: Property cannot be changed while SQLStatement.executing is true.

我已经试过了SQLEvent.RESULT创建一个事件处理程序,我的想法是,是如何的结果会得到从数据库返回,因此执行()将返回错误 - 没”工作。

这是否意味着我想改变我的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(); 
      } 

     } 

流是FILESTREAM
我试图读取一个文本,并把每行到一个新的sqlite的表行。
我也尝试使用sqlStatement.parameters作为替代方式来做我的插入查询,但没有运气。引发不同的错误:

Error #3110: Operation cannot be performed while SQLStatement.executing is true.

回答

0

尝试cancel()

+0

只是试了一下,没有工作。但我很高兴,因为我不想取消sqlstatement.execute()。我希望它在每次再次被解雇之前完成 – marauder 2009-09-07 22:52:35

0

万一任何人来这里看,我想我会张贴我的解决方案。

简单地改变从connection.openAsync()的SQL连接到connection.open()

这摆脱了错误的,我

+1

你所做的是从异步模式变为非异步模式。虽然这对小应用程序来说很好,但在使用较大的数据库时,您希望保持异步。 – BadmintonCat 2011-08-02 10:34:00

1

其更好地为每个查询的新SQLStatment而不是重用的SQLStatement。
它也应该在OpenAsyn模式下工作。

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

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

当使用prefetch> 0调用execute()时,只有当整个结果集已被返回时,execution()才会返回false。例如,execute(10)将返回10行。如果execution()为true,那意味着有更多的数据,并且您需要调用next()以获得接下来的10行。继续调用Next(),直到执行()为false。你可以随时调用cancel()来提前退出(如果你只想要前10行)。

相关问题