Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
Embedded Database | 121

stmt.text = "INSERT INTO contact VALUES ( " +
"NULL, " +
"’" + first + "’, " +
"’" + last + "’ )";

// Track state
state = INSERT_DATA;
stmt.execute();

}

After successfully executing a database statement, the
SQLResultEvent.RESULTevent will be triggered. If an error
occurs, theSQLStatusEvent.STATUSevent will be raised. By
tracking the state, the method designed to handle the result
can determine the appropriate action(s) to take. In the case
of inserting new data, this may be user notification and
updating of the user interface:


<html>
<head>

<title>Storing Database Data</title>
<script type="text/javascript" src="AIRAliases.js">
</script>

<script>
var db = null;
var stmt = null

var NONE = -1;
var CREATE_SCHEMA = 0;
var INSERT_DATA = 1;

var state = NONE;

function doDbOpen( event )
{
stmt =new air.SQLStatement();
stmt.addEventListener( air.SQLErrorEvent.ERROR,
doStmtError );
stmt.addEventListener( air.SQLEvent.RESULT,
doStmtResult );

stmt.sqlConnection = db;
stmt.text = "CREATE TABLE IF NOT EXISTS contact ( " +
Free download pdf