PDA

View Full Version : AIR, SQLite, and Ext stores?



HeathT
29 Aug 2008, 7:47 AM
Hey gang

I'm having some problems bridging the gap between AIR and Ext when it comes to pulling data from a local SQLite DB. There is nothing on the forums, that I can find, which discusses this. I also do not see anything in the API that would indicate there is a "hook" for that.

I have been able to read and write data, tables, and the DB file itself from within the application using the AIR API.

Example code:


var localConn = new air.SQLConnection();

localConn.addEventListener(air.SQLEvent.OPEN, openHandler);
localConn.addEventListener(air.SQLErrorEvent.ERROR, errorHandler);

var dbFile = air.File.applicationStorageDirectory.resolvePath("localData2.db");

localConn.openAsync(dbFile);

function openHandler(event){
air.Introspector.Console.log('the database was created successfully');
}

function errorHandler(event){
air.Introspector.Console.log('Error message: ' + event,error.message);
}

var createStmt = new air.SQLStatement();
createStmt.sqlConnection = localConn;

var sql =
"CREATE TABLE IF NOT EXISTS employees (" +
"empId INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstName TEXT, " +
"lastName TEXT, " +
"salary NUMERIC CHECK (salary > 0)" +
")";
createStmt.text = sql;

createStmt.addEventListener(air.SQLEvent.RESULT, createResult);
createStmt.addEventListener(air.SQLErrorEvent.ERROR, createError);

createStmt.execute();



I have also been able to set up a data connection using Ext by extending the JsonStore.


tx.data.LocalStore = Ext.extend(Ext.data.JsonStore, {
constructor: function() {
tx.data.LocalStore.superclass.constructor.call(this, {
sortInfo: {field: 'empID', direction: 'ASC'},
storeId: 'thisLocalStore',
id: 'empID'
});
this.conn = tx.data.conn;
this.proxy = new Ext.sql.Proxy(tx.data.conn, 'employees', 'empID', this);
},

init: function(){
this.load({
callback: function() {
// Ext.Msg.alert('Number of Records', 'There are ' + this.getCount() + ' in the table.');
}
});
}
});

tx.data.conn = Ext.sql.Connection.getInstance();

tx.data.LocalStore = new tx.data.LocalStore();



However this yields no results that I can find. Though, it doesn't error out.

It's important to point out, that I am not expecting these two code snippets to work with one another. They are intended to function separately and they were each an attempt to bridge the gap as proof of concept.


I am using the introspector and I am very familiar with it and firebug (which are fairly similar).

Animal, rip into me if I've done it all wrong and help straighten me out! Jack, I'm using your Tasks example as a loose guide as to what I need to be doing and I'm probably missing something vital.

If anyone has any ideas or you are "in the know", any help would be great!

devnull
29 Aug 2008, 9:45 AM
Have you looked at the Ext.sql stuff defined in the source? Its apparently not documented in the API docs, but its there.

HeathT
29 Aug 2008, 10:24 AM
Have you looked at the Ext.sql stuff defined in the source? Its apparently not documented in the API docs, but its there.

The Ext.sql stuff in the Ext-AIR.js? Yes sir, I have. Maybe I missed something. I will look at it again.