source: trunk/web/addons/job_monarch/lib/extjs/examples/tasks/db/ext-gears-db.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

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