SQLStatementExecutionException:SQLStatement could not be executed due to an invalid state
Monday, April 20th, 2009I am using the AIR SQL framework developed by Eric J. Feminella. I create my “UserSQLDAO” derived from “AbstractAsynchronousSQLDAO” and start an asynchronous “select” query like “SELECT * FROM users” by executing a defined SQLStatement. However, I can not get the result one time and the SQLStatement is always executing. So if I execute this SQLStatement again, I will receive the exception showed as the title.
After a great searching work, I find nothing helpful. At last, I notice these words below mentioned here.
When the statement’s text property is a SELECT statement, this value indicates how many rows are returned at one time by the statement. The default value is -1, indicating that all the result rows are returned at one time.
I open the source file of class “AbstractAsynchronousSQLDAO”, find “statement.execute( 1, responder );” in the definition of method “execute”. After I set “1″ to “-1″, all bugs are cleared. I feel the sunshine on the next morning.
Below is the class definition I modified from the original file “AbstractAsynchronousSQLDAO.as”. The mokey patch trick is used to hack the air.sql.swc.
/*
Copyright (c) 2006 - 2008 Eric J. Feminella <eric@ericfeminella.com>
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@internal
*/
package com.ericfeminella.sql.dao
{
import flash.data.SQLMode;
import flash.data.SQLStatement;
import flash.filesystem.File;
import flash.net.Responder;
import flash.data.SQLConnection;
/**
*
* <code>AbstractAsynchronousSQLDAO</code> provides an abstraction of
* an asynchronous SQL DAO implementation.
*
*/
public class AbstractAsynchronousSQLDAO extends AbstractSQLDAO
{
/**
*
* Defines the <code>Responder</code> instance which handles
* <code>AbstractAsynchronousSQLDAO</code> SQL operation responses.
*
* @see flash.net.Responder
*
*/
protected var _responder:Responder;
/**
*
* <code>AbstractAsynchronousSQLDAO</code> constructor requires the
* databasePath from which the database connection is made as well as
* an optional <code>ISQLConnectionResponder</code> for handling the
* connection response.
*
* @param the path from which the database connection is made
*
*/
public function AbstractAsynchronousSQLDAO(connection:SQLConnection, databaseFile:File = null)
{
super( connection );
if ( !connection.connected )
{
connection.openAsync( databaseFile, SQLMode.CREATE, new Responder( openResult, openFault ) );
}
}
/**
*
* Assigns a reference to the <code>Responder</code> instance which
* handles SQL operation responses.
*
* @see flash.net.Responder
*
*/
public function set responder(responder:Responder) : void
{
_responder = responder;
}
/**
*
* Retrieves a reference to the <code>Responder</code> instance which
* handles SQL operation responses.
*
* @return flash.net.Responder
*
*/
public function get responder() : Responder
{
return _responder;
}
/**
*
* Convenience method which executes a prepared SQL statement against a local
* SQL Lite database
*
* @param SQL
* @param args
*
*/
public function execute(statement:SQLStatement, …parameters) : void
{
applyStatementParameters.apply( null, [ statement ].concat( parameters ) );
////////////////////////////////////////
// ORIGINAL:
// statement.execute( 1, responder );
// MODIFIED:
statement.execute( -1, responder );
//
// Because I want the “select” sql
// statement returns all the rows I
// requested.
//
////////////////////////////////////////
}
}
}


