[625] | 1 | /*! |
---|
| 2 | * Ext JS Library 3.0.0 |
---|
| 3 | * Copyright(c) 2006-2009 Ext JS, LLC |
---|
| 4 | * licensing@extjs.com |
---|
| 5 | * http://www.extjs.com/license |
---|
| 6 | */ |
---|
| 7 | Ext.data.GearsDB = Ext.extend(Ext.data.SqlDB, { |
---|
| 8 | // abstract methods |
---|
| 9 | open : function(db, cb, scope){ |
---|
| 10 | this.conn = google.gears.factory.create('beta.database', '1.0'); |
---|
| 11 | this.conn.open(db); |
---|
| 12 | this.openState = true; |
---|
| 13 | Ext.callback(cb, scope, [this]); |
---|
| 14 | this.fireEvent('open', this); |
---|
| 15 | }, |
---|
| 16 | |
---|
| 17 | close : function(){ |
---|
| 18 | this.conn.close(); |
---|
| 19 | this.fireEvent('close', this); |
---|
| 20 | }, |
---|
| 21 | |
---|
| 22 | exec : function(sql, cb, scope){ |
---|
| 23 | this.conn.execute(sql).close(); |
---|
| 24 | Ext.callback(cb, scope, [true]); |
---|
| 25 | }, |
---|
| 26 | |
---|
| 27 | execBy : function(sql, args, cb, scope){ |
---|
| 28 | this.conn.execute(sql, args).close(); |
---|
| 29 | Ext.callback(cb, scope, [true]); |
---|
| 30 | }, |
---|
| 31 | |
---|
| 32 | query : function(sql, cb, scope){ |
---|
| 33 | var rs = this.conn.execute(sql); |
---|
| 34 | var r = this.readResults(rs); |
---|
| 35 | Ext.callback(cb, scope, [r]); |
---|
| 36 | return r; |
---|
| 37 | }, |
---|
| 38 | |
---|
| 39 | queryBy : function(sql, args, cb, scope){ |
---|
| 40 | var rs = this.conn.execute(sql, args); |
---|
| 41 | var r = this.readResults(rs); |
---|
| 42 | Ext.callback(cb, scope, [r]); |
---|
| 43 | return r; |
---|
| 44 | }, |
---|
| 45 | |
---|
| 46 | readResults : function(rs){ |
---|
| 47 | var r = []; |
---|
| 48 | if(rs){ |
---|
| 49 | var c = rs.fieldCount(); |
---|
| 50 | // precache field names |
---|
| 51 | var fs = []; |
---|
| 52 | for(var i = 0; i < c; i++){ |
---|
| 53 | fs[i] = rs.fieldName(i); |
---|
| 54 | } |
---|
| 55 | // read the data |
---|
| 56 | while(rs.isValidRow()){ |
---|
| 57 | var o = {}; |
---|
| 58 | for(var i = 0; i < c; i++){ |
---|
| 59 | o[fs[i]] = rs.field(i); |
---|
| 60 | } |
---|
| 61 | r[r.length] = o; |
---|
| 62 | rs.next(); |
---|
| 63 | } |
---|
| 64 | rs.close(); |
---|
| 65 | } |
---|
| 66 | return r; |
---|
| 67 | }, |
---|
| 68 | |
---|
| 69 | // protected/inherited method |
---|
| 70 | isOpen : function(){ |
---|
| 71 | return this.openState; |
---|
| 72 | }, |
---|
| 73 | |
---|
| 74 | getTable : function(name, keyName){ |
---|
| 75 | return new Ext.data.SqlDB.Table(this, name, keyName); |
---|
| 76 | } |
---|
| 77 | }); |
---|