Prev | Current Page 543 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

request( sql );
// if the returned value is zero, rollback the transaction
if ( rec.getIntResult( 0 ) == 0 )
cnx.rollback();
else
cnx.commit();
// close the database connection
cnx.close();
}
}
As you can see, much of the code isn ??™ t so different from what you ??™ ve already accomplished with
previous examples. The main difference is, before any of the SQL code was executed, you started a new
transaction for the current Connection object. This transaction runs until commit or rollback is called,
or the Connection object is closed, either with the close method or by force, such as an application
crash. Any insert, update or delete statement executed after the startTransaction call will be rolled
back at any of these points except when commit is called successfully. This provides complete protection
for your data integrity.
Another new feature in the aforementioned Transaction class that has not yet been covered involves
dealing with data returned from an executed query. You ??™ ll look at this in great detail, next.


Pages:
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555