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.

102 lines
2.5 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.AirDB = Ext.extend(Ext.data.SqlDB, {
  8. open : function(db, cb, scope){
  9. this.conn = new air.SQLConnection();
  10. var file = air.File.applicationResourceDirectory.resolve(db);
  11. this.conn.addEventListener(air.SQLEvent.OPEN, this.onOpen.createDelegate(this, [cb, scope]));
  12. this.conn.addEventListener(air.SQLEvent.CLOSE, this.onClose.createDelegate(this));
  13. this.conn.open(file, true);
  14. },
  15. close : function(){
  16. this.conn.close();
  17. },
  18. onOpen : function(cb, scope){
  19. this.openState = true;
  20. Ext.callback(cb, scope, [this]);
  21. this.fireEvent('open', this);
  22. },
  23. onClose : function(){
  24. this.fireEvent('close', this);
  25. },
  26. onError : function(e, stmt, type, cb, scope){
  27. Ext.callback(cb, scope, [false, e, stmt]);
  28. },
  29. onResult : function(e, stmt, type, cb, scope){
  30. if(type == 'exec'){
  31. Ext.callback(cb, scope, [true, e, stmt]);
  32. }else{
  33. var r = [];
  34. var result = stmt.getResult();
  35. if(result && result.data){
  36. var len = result.data.length;
  37. for(var i = 0; i < len; i++) {
  38. r[r.length] = result.data[i];
  39. }
  40. }
  41. Ext.callback(cb, scope, [r, e, stmt]);
  42. }
  43. },
  44. createStatement : function(type, cb, scope){
  45. var stmt = new air.SQLStatement();
  46. stmt.addEventListener(air.SQLErrorEvent.ERROR, this.onError.createDelegate(this, [stmt, type, cb, scope], true));
  47. stmt.addEventListener(air.SQLEvent.RESULT, this.onResult.createDelegate(this, [stmt, type, cb, scope], true));
  48. stmt.sqlConnection = this.conn;
  49. return stmt;
  50. },
  51. exec : function(sql, cb, scope){
  52. var stmt = this.createStatement('exec', cb, scope);
  53. stmt.text = sql;
  54. stmt.execute();
  55. },
  56. execBy : function(sql, args, cb, scope){
  57. var stmt = this.createStatement('exec', cb, scope);
  58. stmt.text = sql;
  59. this.addParams(stmt, args);
  60. stmt.execute();
  61. },
  62. query : function(sql, cb, scope){
  63. var stmt = this.createStatement('query', cb, scope);
  64. stmt.text = sql;
  65. stmt.execute(this.maxResults);
  66. },
  67. queryBy : function(sql, args, cb, scope){
  68. var stmt = this.createStatement('query', cb, scope);
  69. stmt.text = sql;
  70. this.addParams(stmt, args);
  71. stmt.execute(this.maxResults);
  72. },
  73. addParams : function(stmt, args){
  74. if(!args){ return; }
  75. for(var key in args){
  76. if(args.hasOwnProperty(key)){
  77. if(!isNaN(key)){
  78. stmt.parameters[parseInt(key)+1] = args[key];
  79. }else{
  80. stmt.parameters[':' + key] = args[key];
  81. }
  82. }
  83. }
  84. return stmt;
  85. }
  86. });