3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"> Ext.data.AirDB = Ext.extend(Ext.data.SqlDB, {
\r
9 open : function(db, cb, scope){
\r
10 this.conn = new air.SQLConnection();
\r
12 var file = air.File.applicationResourceDirectory.resolve(db);
\r
14 this.conn.addEventListener(air.SQLEvent.OPEN, this.onOpen.createDelegate(this, [cb, scope]));
\r
15 this.conn.addEventListener(air.SQLEvent.CLOSE, this.onClose.createDelegate(this));
\r
16 this.conn.open(file, true);
\r
23 onOpen : function(cb, scope){
\r
24 this.openState = true;
\r
25 Ext.callback(cb, scope, [this]);
\r
26 this.fireEvent('open', this);
\r
29 onClose : function(){
\r
30 this.fireEvent('close', this);
\r
33 onError : function(e, stmt, type, cb, scope){
\r
34 Ext.callback(cb, scope, [false, e, stmt]);
\r
37 onResult : function(e, stmt, type, cb, scope){
\r
39 Ext.callback(cb, scope, [true, e, stmt]);
\r
42 var result = stmt.getResult();
\r
43 if(result && result.data){
\r
44 var len = result.data.length;
\r
45 for(var i = 0; i < len; i++) {
\r
46 r[r.length] = result.data[i];
\r
49 Ext.callback(cb, scope, [r, e, stmt]);
\r
53 createStatement : function(type, cb, scope){
\r
55 var stmt = new air.SQLStatement();
\r
57 stmt.addEventListener(air.SQLErrorEvent.ERROR, this.onError.createDelegate(this, [stmt, type, cb, scope], true));
\r
58 stmt.addEventListener(air.SQLEvent.RESULT, this.onResult.createDelegate(this, [stmt, type, cb, scope], true));
\r
60 stmt.sqlConnection = this.conn;
\r
65 exec : function(sql, cb, scope){
\r
66 var stmt = this.createStatement('exec', cb, scope);
\r
71 execBy : function(sql, args, cb, scope){
\r
72 var stmt = this.createStatement('exec', cb, scope);
\r
74 this.addParams(stmt, args);
\r
78 query : function(sql, cb, scope){
\r
79 var stmt = this.createStatement('query', cb, scope);
\r
81 stmt.execute(this.maxResults);
\r
84 queryBy : function(sql, args, cb, scope){
\r
85 var stmt = this.createStatement('query', cb, scope);
\r
87 this.addParams(stmt, args);
\r
88 stmt.execute(this.maxResults);
\r
91 addParams : function(stmt, args){
\r
92 if(!args){ return; }
\r
93 for(var key in args){
\r
94 if(args.hasOwnProperty(key)){
\r
96 stmt.parameters[parseInt(key)+1] = args[key];
\r
98 stmt.parameters[':' + key] = args[key];
\r