source: trunk/web/addons/job_monarch/lib/extjs/air/src/sql/Connection.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.1 KB
Line 
1/*
2 * Ext JS Library 0.30
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9// Abstract base class for Connection classes
10Ext.sql.Connection = function(config){
11        Ext.apply(this, config);
12        Ext.sql.Connection.superclass.constructor.call(this);
13
14        this.addEvents({
15                open : true,
16                close: true
17        });
18};
19
20Ext.extend(Ext.sql.Connection, Ext.util.Observable, {
21        maxResults: 10000,
22        openState : false,
23
24    // abstract methods
25    open : function(file){
26        },
27
28        close : function(){
29        },
30
31    exec : function(sql){
32        },
33
34        execBy : function(sql, args){
35        },
36
37        query : function(sql){
38        },
39
40        queryBy : function(sql, args){
41        },
42
43    // protected/inherited method
44    isOpen : function(){
45                return this.openState;
46        },
47
48        getTable : function(name, keyName){
49                return new Ext.sql.Table(this, name, keyName);
50        },
51
52        createTable : function(o){
53                var tableName = o.name;
54                var keyName = o.key;
55                var fs = o.fields;
56                if(!Ext.isArray(fs)){ // Ext fields collection
57                        fs = fs.items;
58                }
59                var buf = [];
60                for(var i = 0, len = fs.length; i < len; i++){
61                        var f = fs[i], s = f.name;
62                        switch(f.type){
63                    case "int":
64                    case "bool":
65                    case "boolean":
66                        s += ' INTEGER';
67                        break;
68                    case "float":
69                        s += ' REAL';
70                        break;
71                    default:
72                        s += ' TEXT';
73                }
74                if(f.allowNull === false || f.name == keyName){
75                        s += ' NOT NULL';
76                }
77                if(f.name == keyName){
78                        s += ' PRIMARY KEY';
79                }
80                if(f.unique === true){
81                        s += ' UNIQUE';
82                }
83
84                buf[buf.length] = s;
85            }
86            var sql = ['CREATE TABLE IF NOT EXISTS ', tableName, ' (', buf.join(','), ')'].join('');
87        this.exec(sql);
88        }
89});
90
91
92Ext.sql.Connection.getInstance = function(db, config){
93    if(Ext.isAir){ // air
94        return new Ext.sql.AirConnection(config);
95    } else { // gears
96        return new Ext.sql.GearsConnection(config);
97    }
98};
Note: See TracBrowser for help on using the repository browser.