Here is the code:
public function insertPlayDetails(e:SQLEvent):void {
var result:SQLResult = e.target.getResult();
if (result != null) {
var row:Object = result.data[0];
fieldsIdArray.push(row.id);
}
numFieldsTotal =
this.GSISFields.concat(this.OffensiveFields.concat(this.DefensiveFields)).length;
updateImportCount = 0;
var playsDetailsArray:Array = new Array;
for (var i:int = 0; i < allDetails.length; i++) {
playsDetailsArray[i] = new Array();
var playDetails:Array = allDetails[i];
var lastPlayId:int = playIdArray[i];
var allFields:Array =
this.GSISFields.concat(this.OffensiveFields.concat(this.DefensiveFields));
//trace("I'm looking for the
playDetails.length: "+allFields.length);
//for (var j:int = 0; j < playDetails.length;
j++) {
for (var j:int = 0; j < allFields.length; j++) {
playsDetailsArray[i][j] = new Object();
playsDetailsArray[i][j].sqlST = new
SQLStatement();
playsDetailsArray[i][j].sqlST.sqlConnection = _sqlConnection;
var fieldId:int = fieldsIdArray[j];
var fieldValue:String = "";
if (j < (playDetails.length - 1)) {
fieldValue = (playDetails[j] as
String).replace(myPattern, "");
}
var adjustedPlayNumber =
allDetails.length - (i+1);
var autoFillCursor:IViewCursor =
autoFillArrayC.createCursor();
autoFillCursor.seek(CursorBookmark.FIRST);
while (!autoFillCursor.afterLast) {
if
((autoFillCursor.current.fieldId == fieldId) &&
(adjustedPlayNumber == autoFillCursor.current.playNumber)) {
fieldValue =
autoFillCursor.current.fieldValue;
}
autoFillCursor.moveNext()
}
playsDetailsArray[i][j].sqlST.text =
"INSERT INTO Details
(playId, fieldId, fieldValue) " +
"Values
('"+lastPlayId+"', '"+fieldId+"', '"+fieldValue+"')";
playsDetailsArray[i][j].sqlST.addEventListener(SQLErrorEvent.ERROR,
insertPlayError);
//if ((i == (allDetails.length - 1)) &&
(j == (playDetails.length
- 1))) {
if ((i == (allDetails.length - 1)) &&
(j == (allFields.length -
1))) {
playsDetailsArray[i][j].sqlST.addEventListener(SQLEvent.RESULT,
insertPlayDone);
}
else {
playsDetailsArray[i][j].sqlST.addEventListener(SQLEvent.RESULT,
updateImportCountFunc);
}
playsDetailsArray[i][j].sqlST.execute();
}
}
}
public function insertPlayError(e:SQLErrorEvent):void {
_gameProxy.writeToDBLog((e.error+" : "+e.text+" :
"+e.target.text));
}
public function badTallyPlayId(e:SQLErrorEvent):void {
_gameProxy.writeToDBLog((e.error+" : "+e.text+" :
"+e.target.text));
}
//public function updateImportCountFunc(e:SQLEvent):void {
public function updateImportCountFunc(e:SQLEvent):void {
_gameProxy.writeToDBLog(e.target.toString());
updateImportCount++;
trace("ImportCount: "+updateImportCount);
//var toCalc:int = updateImportCount;
//var allFields:Array =
this.GSISFields.concat(this.OffensiveFields.concat(this.DefensiveFields));
_gameProxy.updateImportProcess((Math.round(updateImportCount/numFieldsTotal)),
numFieldsTotal);
}
--- In [email protected], Sid Maskit <[EMAIL PROTECTED]> wrote:
>
> How about posting the relevant code. Also, am I right in assuming
that this is in AIR, and that you are using its local database?
>
> Sid Maskit
> Partner
> CraftySpace
> Better Websites for a Better World
> http://www.CraftySpace.com
> blog: http://smaskit.blogspot.com/
>
>
>
> ----- Original Message ----
> From: Josh Millstein <[EMAIL PROTECTED]>
> To: "[email protected]" <[email protected]>
> Sent: Thursday, July 31, 2008 9:59:09 AM
> Subject: [flexcoders] SQL crashing program
>
>
> I have this weird deal going on right now. I'm running through a
for loop
> creating a bunch of sql statements (within an exclusive transaction)
with
> eventlisteners for the results and errors. The result eventlistener is
> relaying the status of the progress through the sql statements
("record x of
> y inserted"). The program crashes when I run the program, but when
I put
> code in the result eventlistener to write sql.text to a file (trying
to see
> if there is a bad sql statement crashing the program) it stopped the
program
> from crashing and everything works well. I don't understand why
that would
> be. The only thing I can think of is that there is some timing
issue that
> I'm skirting around with writing to a file in between each sql
statement.
> Does anybody have any idea why putting the code to write to a dblog file
> would make the program work? I'm sure it's is just that piece of
code as
> well. Comment it and it crashes, put it back and it works.
>
> Weird.
>
> --
> [EMAIL PROTECTED] .com
>