3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.sql.Table = function(conn, name, keyName){
\r
11 this.keyName = keyName;
\r
14 Ext.sql.Table.prototype = {
\r
15 update : function(o){
\r
16 var clause = this.keyName + " = ?";
\r
17 return this.updateBy(o, clause, [o[this.keyName]]);
\r
20 updateBy : function(o, clause, args){
\r
21 var sql = "UPDATE " + this.name + " set ";
\r
22 var fs = [], a = [];
\r
24 if(o.hasOwnProperty(key)){
\r
25 fs[fs.length] = key + ' = ?';
\r
26 a[a.length] = o[key];
\r
29 for(var key in args){
\r
30 if(args.hasOwnProperty(key)){
\r
31 a[a.length] = args[key];
\r
34 sql = [sql, fs.join(','), ' WHERE ', clause].join('');
\r
35 return this.conn.execBy(sql, a);
\r
38 insert : function(o){
\r
39 var sql = "INSERT into " + this.name + " ";
\r
40 var fs = [], vs = [], a = [];
\r
42 if(o.hasOwnProperty(key)){
\r
43 fs[fs.length] = key;
\r
44 vs[vs.length] = '?';
\r
45 a[a.length] = o[key];
\r
48 sql = [sql, '(', fs.join(','), ') VALUES (', vs.join(','), ')'].join('');
\r
49 return this.conn.execBy(sql, a);
\r
52 lookup : function(id){
\r
53 return this.selectBy('where ' + this.keyName + " = ?", [id])[0] || null;
\r
56 exists : function(id){
\r
57 return !!this.lookup(id);
\r
61 if(this.exists(o[this.keyName])){
\r
68 select : function(clause){
\r
69 return this.selectBy(clause, null);
\r
72 selectBy : function(clause, args){
\r
73 var sql = "select * from " + this.name;
\r
75 sql += ' ' + clause;
\r
78 return this.conn.queryBy(sql, args);
\r
81 remove : function(clause){
\r
82 this.deleteBy(clause, null);
\r
85 removeBy : function(clause, args){
\r
86 var sql = "delete from " + this.name;
\r
88 sql += ' where ' + clause;
\r
91 this.conn.execBy(sql, args);
\r