1 Reply Latest reply on Jun 17, 2008 9:15 AM by andyd273

    AIR not catching the SQLErrorEvent

    andyd273
      I have an AIR app that gets data from the user and stores it in a local SQLite database.
      It works pretty well, unless the data is already present.
      Since I don't know of a way to check if the data exists before I do the insert, I have it set up to just do the insert:
      if(resultObj.getkey.Key != "null" && resultObj.getkey.Key != ''){
      sqlStatement = new SQLStatement();
      sqlStatement.sqlConnection = conn;
      var sql:String = "Insert Into OGo (ID, code, key, path) values (1,'" + txtRegEnter.text + "', '" + resultObj.getkey.Key + "', '" + dbFile.nativePath + "')"
      sqlStatement.text=sql;
      sqlStatement.addEventListener(SQLEvent.RESULT, selectResult);
      sqlStatement.addEventListener(SQLErrorEvent.ERROR, selectError);
      sqlStatement.execute();
      }

      private function selectError(event:SQLErrorEvent):void{
      var sql:String
      if(event.text=="Abort due to constraint violation."){
      sqlStatement = new SQLStatement();
      sqlStatement.sqlConnection = conn;
      sql = "Update OWGo SET code = '" + txtRegEnter.text + "', key = '" + Key + "', path = '" + dbFile.nativePath + "' WHERE ID=1" //autoincrement
      sqlStatement.text=sql;
      sqlStatement.addEventListener(SQLEvent.RESULT, selectResult);
      sqlStatement.addEventListener(SQLErrorEvent.ERROR, selectError);
      sqlStatement.execute();
      }
      }

      But instead of pulling up the selectError function, I get an error message saying

      SQLError: 'Error #3131: Abort due to constraint violation.', details:'PRIMARY KEY must be unique', operation:'execute'
      at flash.data::SQLStatement/internalExecute()
      at flash.data::SQLStatement/execute()
      at OWGOnline/getSetKeyHandler()[H:\Shared Data\Flex Builder Projects\GOnline\src\GOnline.mxml:244]
      at OWGOnline/__getSetKey_result()[H:\Shared Data\Flex Builder Projects\GOnline\src\OWGOnline.mxml:386]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.rpc.http.mxml::HTTPService/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.0.x\frameworks\pro jects\rpc\src\mx\rpc\http\mxml\HTTPService.as:275
      at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.0.x\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:191
      at mx.rpc::Responder/result()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:4 1]
      at mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:74]
      at DirectHTTPMessageResponder/completeHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:381]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()

      This did all work really well under the beta, so I don't know why it's not working now.