(function(e){if(e.BX.dataBase)return;var t=e.BX;t.dataBase=function(t){this.tableList=[];this.jsonFields={};if(typeof e.SQLitePlugin!="undefined"&&typeof e.SQLitePlugin.openDatabase=="function"){this.dbObject=e.SQLitePlugin.openDatabase(t.name,t.version,t.displayName,t.capacity);this.dbBandle="SQLitePlugin"}else if(typeof e.openDatabase!="undefined"){this.dbBandle="openDatabase";this.dbObject=e.openDatabase(t.name,t.version,t.displayName,t.capacity)}else{this.dbBandle="undefined";this.dbObject=null}};t.dataBase.create=function(i){if(typeof e.openDatabase!="undefined"||typeof e.SQLitePlugin!="undefined"&&typeof e.SQLitePlugin.openDatabase=="function"){return new t.dataBase(i)}else{return null}};t.dataBase.prototype.setJsonFields=function(e,i){if(typeof i=="string"){if(i==""){i=[]}else{i=[i]}}if(e&&t.type.isArray(i)){e=e.toString().toUpperCase();this.jsonFields[e]=[];if(i.length>0){for(var a=0;a-1){i(true,e);a.fulfill(e)}else{i(false,e);a.reject(e)}};if(this.tableList.length<=0){this.getTableList().then(s)}else{s(this.tableList)}return a};t.dataBase.prototype.getTableList=function(e){var i=new t.Promise;if(typeof e!="function"){e=function(){}}var a=e;this.query({query:"SELECT tbl_name from sqlite_master WHERE type = 'table'",values:[]}).then(function(e){this.tableList=[];if(e.result.count>0){for(var t=0;t0){l=s[p]}if(l.length>0){if(u.length>0)u+=","+l.toUpperCase();else u=l.toUpperCase()}}}f="CREATE TABLE IF NOT EXISTS "+o.toUpperCase()+" ("+u+") ";break}case"drop":{f="DROP TABLE IF EXISTS "+o.toUpperCase();break}case"select":{f="SELECT "+this.getValueArrayString(s,"*")+" FROM "+o.toUpperCase()+" "+this.getFilter(a);i=this.getValues([a]);break}case"insert":{var h=0;var y=0;var g="";if(t.type.isArray(n)){i=this.getValues(n,"insert");for(var d in n[0]){y++}h=n.length;g=this.getKeyString(n[0])}else{i=this.getValues([n],"insert");h=1;y=i.length;g=this.getKeyString(n)}f="INSERT INTO "+o.toUpperCase()+" ("+g+") VALUES %values%";var v=[];var b=[];for(var d=0;d0?", ":"")+(n.toUpperCase()+"="+"?");if(i.length==0&&a.length>0)i=a;i+=r;s++}}return i};t.dataBase.prototype.getFilter=function(e){var t="";var i="WHERE ";if(typeof e=="object"){var a=0;for(var s in e){var n="";var r=1;if(typeof e[s]=="object"){r=e[s].length}for(var o=0;o0?n+" OR ":"(")+(s.toUpperCase()+"="+"?");if(o+1==r)n+=")"}t+=n;a++}}else if(typeof e=="string"){t=e}return t==""?"":"WHERE "+t};t.dataBase.prototype.getKeyString=function(e,i){var a="";if(!i)i="";if(t.type.isArray(e)){for(var s=0;s0)a+=","+n.toUpperCase();else a=n.toUpperCase()}}}else if(typeof e=="object"){for(var n in e){if(a.length>0)a+=","+n.toUpperCase();else a=n.toUpperCase()}}if(a.length==0)a=i;return a};t.dataBase.prototype.getValueArrayString=function(e,t){var i="";if(!t)t="";if(typeof e=="object"){for(var a=0;a0)i+=","+e[a].toUpperCase();else i=e[a].toUpperCase()}}if(i.length==0)i=t;return i};t.dataBase.prototype.getValues=function(e,i){i=i||"undefined";var a=[];for(var s=0;s=0){a.count=n;a.items=[];for(var r=0;r