SQLite connection
SQLite connection
I am creating an AIR app that uses a SQLite database. I have a connection to the database in an html file that does display the data, however using that as an ajaxsource won't render any data. Here is my SQLite connection file, is there any example of how to call this file to render the data?
[code]
Accessing Data in a Database
body {
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 11px;
color: #0B333C;
}
var db = null;
var stmt = null
var NONE = -1;
var CREATE_SCHEMA = 0;
var SELECT_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 cotindex ( ' + 'cotnumber INTEGER PRIMARY KEY, ' + 'date DATE, ' + 'driller TEXT, ' + 'lease TEXT, ' + 'stopnum TEXT )';
state = CREATE_SCHEMA;
stmt.execute();
}
function doLoad()
{
var file = air.File.applicationStorageDirectory.resolvePath( 'cotmobile' );
db = new air.SQLConnection();
db.addEventListener( air.SQLEvent.OPEN, doDbOpen );
db.open( file, air.SQLMode.CREATE );
}
function doStmtResult( event )
{
var elem = null;
var result = null;
switch( state )
{
case CREATE_SCHEMA:
stmt.text = 'SELECT * FROM cotindex';
state = SELECT_DATA;
stmt.execute();
break;
case SELECT_DATA:
result = stmt.getResult();
if( result.data != null )
{
for( var c = 0; c < result.data.length;
c++ )
{
elem = document.createElement( 'div' );
elem.innerText = result.data[c].cotnumber +
' ' + result.data[c].date +
' ' + result.data[c].driller +
' ' + result.data[c].lease +
' ' + result.data[c].stopnum;
document.body.appendChild( elem );
}
}
state = NONE;
break;
default:
state = NONE;
break;
}
}
function doStmtError( event )
{
alert( 'There has been a problem executing a statement:\n' + event.error.message );
}
[/code]
[code]
Accessing Data in a Database
body {
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 11px;
color: #0B333C;
}
var db = null;
var stmt = null
var NONE = -1;
var CREATE_SCHEMA = 0;
var SELECT_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 cotindex ( ' + 'cotnumber INTEGER PRIMARY KEY, ' + 'date DATE, ' + 'driller TEXT, ' + 'lease TEXT, ' + 'stopnum TEXT )';
state = CREATE_SCHEMA;
stmt.execute();
}
function doLoad()
{
var file = air.File.applicationStorageDirectory.resolvePath( 'cotmobile' );
db = new air.SQLConnection();
db.addEventListener( air.SQLEvent.OPEN, doDbOpen );
db.open( file, air.SQLMode.CREATE );
}
function doStmtResult( event )
{
var elem = null;
var result = null;
switch( state )
{
case CREATE_SCHEMA:
stmt.text = 'SELECT * FROM cotindex';
state = SELECT_DATA;
stmt.execute();
break;
case SELECT_DATA:
result = stmt.getResult();
if( result.data != null )
{
for( var c = 0; c < result.data.length;
c++ )
{
elem = document.createElement( 'div' );
elem.innerText = result.data[c].cotnumber +
' ' + result.data[c].date +
' ' + result.data[c].driller +
' ' + result.data[c].lease +
' ' + result.data[c].stopnum;
document.body.appendChild( elem );
}
}
state = NONE;
break;
default:
state = NONE;
break;
}
}
function doStmtError( event )
{
alert( 'There has been a problem executing a statement:\n' + event.error.message );
}
[/code]
This discussion has been closed.