--- /dev/null
+<html>\r
+<head>\r
+ <title>The source code</title>\r
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
+</head>\r
+<body onload="prettyPrint();">\r
+ <pre class="prettyprint lang-js"> Ext.data.AirDB = Ext.extend(Ext.data.SqlDB, {\r
+ open : function(db, cb, scope){\r
+ this.conn = new air.SQLConnection();\r
+\r
+ var file = air.File.applicationResourceDirectory.resolve(db);\r
+\r
+ this.conn.addEventListener(air.SQLEvent.OPEN, this.onOpen.createDelegate(this, [cb, scope]));\r
+ this.conn.addEventListener(air.SQLEvent.CLOSE, this.onClose.createDelegate(this));\r
+ this.conn.open(file, true);\r
+ },\r
+\r
+ close : function(){\r
+ this.conn.close();\r
+ },\r
+\r
+ onOpen : function(cb, scope){\r
+ this.openState = true;\r
+ Ext.callback(cb, scope, [this]);\r
+ this.fireEvent('open', this);\r
+ },\r
+\r
+ onClose : function(){\r
+ this.fireEvent('close', this);\r
+ },\r
+\r
+ onError : function(e, stmt, type, cb, scope){\r
+ Ext.callback(cb, scope, [false, e, stmt]);\r
+ },\r
+\r
+ onResult : function(e, stmt, type, cb, scope){\r
+ if(type == 'exec'){\r
+ Ext.callback(cb, scope, [true, e, stmt]);\r
+ }else{\r
+ var r = [];\r
+ var result = stmt.getResult();\r
+ if(result && result.data){\r
+ var len = result.data.length;\r
+ for(var i = 0; i < len; i++) {\r
+ r[r.length] = result.data[i];\r
+ }\r
+ }\r
+ Ext.callback(cb, scope, [r, e, stmt]);\r
+ }\r
+ },\r
+\r
+ createStatement : function(type, cb, scope){\r
+\r
+ var stmt = new air.SQLStatement();\r
+\r
+ stmt.addEventListener(air.SQLErrorEvent.ERROR, this.onError.createDelegate(this, [stmt, type, cb, scope], true));\r
+ stmt.addEventListener(air.SQLEvent.RESULT, this.onResult.createDelegate(this, [stmt, type, cb, scope], true));\r
+\r
+ stmt.sqlConnection = this.conn;\r
+\r
+ return stmt;\r
+ },\r
+\r
+ exec : function(sql, cb, scope){\r
+ var stmt = this.createStatement('exec', cb, scope);\r
+ stmt.text = sql;\r
+ stmt.execute();\r
+ },\r
+\r
+ execBy : function(sql, args, cb, scope){\r
+ var stmt = this.createStatement('exec', cb, scope);\r
+ stmt.text = sql;\r
+ this.addParams(stmt, args);\r
+ stmt.execute();\r
+ },\r
+\r
+ query : function(sql, cb, scope){\r
+ var stmt = this.createStatement('query', cb, scope);\r
+ stmt.text = sql;\r
+ stmt.execute(this.maxResults);\r
+ },\r
+\r
+ queryBy : function(sql, args, cb, scope){\r
+ var stmt = this.createStatement('query', cb, scope);\r
+ stmt.text = sql;\r
+ this.addParams(stmt, args);\r
+ stmt.execute(this.maxResults);\r
+ },\r
+\r
+ addParams : function(stmt, args){\r
+ if(!args){ return; }\r
+ for(var key in args){\r
+ if(args.hasOwnProperty(key)){\r
+ if(!isNaN(key)){\r
+ stmt.parameters[parseInt(key)+1] = args[key];\r
+ }else{\r
+ stmt.parameters[':' + key] = args[key];\r
+ }\r
+ }\r
+ }\r
+ return stmt;\r
+ }\r
+});</pre> \r
+</body>\r
+</html>
\ No newline at end of file