2 * Ext JS Library 0.30
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
9 Ext.sql.Table = function(conn, name, keyName){
\r
12 this.keyName = keyName;
\r
15 Ext.sql.Table.prototype = {
\r
16 update : function(o){
\r
17 var clause = this.keyName + " = ?";
\r
18 return this.updateBy(o, clause, [o[this.keyName]]);
\r
21 updateBy : function(o, clause, args){
\r
22 var sql = "UPDATE " + this.name + " set ";
\r
23 var fs = [], a = [];
\r
25 if(o.hasOwnProperty(key)){
\r
26 fs[fs.length] = key + ' = ?';
\r
27 a[a.length] = o[key];
\r
30 for(var key in args){
\r
31 if(args.hasOwnProperty(key)){
\r
32 a[a.length] = args[key];
\r
35 sql = [sql, fs.join(','), ' WHERE ', clause].join('');
\r
36 return this.conn.execBy(sql, a);
\r
39 insert : function(o){
\r
40 var sql = "INSERT into " + this.name + " ";
\r
41 var fs = [], vs = [], a = [];
\r
43 if(o.hasOwnProperty(key)){
\r
44 fs[fs.length] = key;
\r
45 vs[vs.length] = '?';
\r
46 a[a.length] = o[key];
\r
49 sql = [sql, '(', fs.join(','), ') VALUES (', vs.join(','), ')'].join('');
\r
50 return this.conn.execBy(sql, a);
\r
53 lookup : function(id){
\r
54 return this.selectBy('where ' + this.keyName + " = ?", [id])[0] || null;
\r
57 exists : function(id){
\r
58 return !!this.lookup(id);
\r
62 if(this.exists(o[this.keyName])){
\r
69 select : function(clause){
\r
70 return this.selectBy(clause, null);
\r
73 selectBy : function(clause, args){
\r
74 var sql = "select * from " + this.name;
\r
76 sql += ' ' + clause;
\r
79 return this.conn.queryBy(sql, args);
\r
82 remove : function(clause){
\r
83 this.deleteBy(clause, null);
\r
86 removeBy : function(clause, args){
\r
87 var sql = "delete from " + this.name;
\r
89 sql += ' where ' + clause;
\r
92 this.conn.execBy(sql, args);
\r