2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
9 Ext.data.AirDB = Ext.extend(Ext.data.SqlDB, {
\r
10 open : function(db, cb, scope){
\r
11 this.conn = new air.SQLConnection();
\r
13 var file = air.File.applicationResourceDirectory.resolve(db);
\r
15 this.conn.addEventListener(air.SQLEvent.OPEN, this.onOpen.createDelegate(this, [cb, scope]));
\r
16 this.conn.addEventListener(air.SQLEvent.CLOSE, this.onClose.createDelegate(this));
\r
17 this.conn.open(file, true);
\r
24 onOpen : function(cb, scope){
\r
25 this.openState = true;
\r
26 Ext.callback(cb, scope, [this]);
\r
27 this.fireEvent('open', this);
\r
30 onClose : function(){
\r
31 this.fireEvent('close', this);
\r
34 onError : function(e, stmt, type, cb, scope){
\r
35 Ext.callback(cb, scope, [false, e, stmt]);
\r
38 onResult : function(e, stmt, type, cb, scope){
\r
40 Ext.callback(cb, scope, [true, e, stmt]);
\r
43 var result = stmt.getResult();
\r
44 if(result && result.data){
\r
45 var len = result.data.length;
\r
46 for(var i = 0; i < len; i++) {
\r
47 r[r.length] = result.data[i];
\r
50 Ext.callback(cb, scope, [r, e, stmt]);
\r
54 createStatement : function(type, cb, scope){
\r
56 var stmt = new air.SQLStatement();
\r
58 stmt.addEventListener(air.SQLErrorEvent.ERROR, this.onError.createDelegate(this, [stmt, type, cb, scope], true));
\r
59 stmt.addEventListener(air.SQLEvent.RESULT, this.onResult.createDelegate(this, [stmt, type, cb, scope], true));
\r
61 stmt.sqlConnection = this.conn;
\r
66 exec : function(sql, cb, scope){
\r
67 var stmt = this.createStatement('exec', cb, scope);
\r
72 execBy : function(sql, args, cb, scope){
\r
73 var stmt = this.createStatement('exec', cb, scope);
\r
75 this.addParams(stmt, args);
\r
79 query : function(sql, cb, scope){
\r
80 var stmt = this.createStatement('query', cb, scope);
\r
82 stmt.execute(this.maxResults);
\r
85 queryBy : function(sql, args, cb, scope){
\r
86 var stmt = this.createStatement('query', cb, scope);
\r
88 this.addParams(stmt, args);
\r
89 stmt.execute(this.maxResults);
\r
92 addParams : function(stmt, args){
\r
93 if(!args){ return; }
\r
94 for(var key in args){
\r
95 if(args.hasOwnProperty(key)){
\r
97 stmt.parameters[parseInt(key)+1] = args[key];
\r
99 stmt.parameters[':' + key] = args[key];
\r