Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.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. close : function(){
  17. this.conn.close();
  18. this.fireEvent('close', this);
  19. },
  20. exec : function(sql, cb, scope){
  21. this.conn.execute(sql).close();
  22. Ext.callback(cb, scope, [true]);
  23. },
  24. execBy : function(sql, args, cb, scope){
  25. this.conn.execute(sql, args).close();
  26. Ext.callback(cb, scope, [true]);
  27. },
  28. query : function(sql, cb, scope){
  29. var rs = this.conn.execute(sql);
  30. var r = this.readResults(rs);
  31. Ext.callback(cb, scope, [r]);
  32. return r;
  33. },
  34. queryBy : function(sql, args, cb, scope){
  35. var rs = this.conn.execute(sql, args);
  36. var r = this.readResults(rs);
  37. Ext.callback(cb, scope, [r]);
  38. return r;
  39. },
  40. readResults : function(rs){
  41. var r = [];
  42. if(rs){
  43. var c = rs.fieldCount();
  44. // precache field names
  45. var fs = [];
  46. for(var i = 0; i < c; i++){
  47. fs[i] = rs.fieldName(i);
  48. }
  49. // read the data
  50. while(rs.isValidRow()){
  51. var o = {};
  52. for(var i = 0; i < c; i++){
  53. o[fs[i]] = rs.field(i);
  54. }
  55. r[r.length] = o;
  56. rs.next();
  57. }
  58. rs.close();
  59. }
  60. return r;
  61. },
  62. // protected/inherited method
  63. isOpen : function(){
  64. return this.openState;
  65. },
  66. getTable : function(name, keyName){
  67. return new Ext.data.SqlDB.Table(this, name, keyName);
  68. }
  69. });