(function(e){if(e.BX.dataBase)return;var t=e.BX;t.dataBase=function(t){this.tableList=[];if(typeof e.openDatabase!="undefined")this.dbObject=e.openDatabase(t.name,t.version,t.displayName,t.capacity)};t.dataBase.prototype.isTableExists=function(e,t){var a=this;var r=function(){var r=a.tableList.length;for(var s=0;s<r;s++){if(a.tableList[s].toUpperCase()==e.toUpperCase()){t(true);return}}t(false)};if(this.tableList.length<=0)this.getTableList(r);else r()};t.dataBase.prototype.getTableList=function(e){var t=this;var a=e;this.query({query:"SELECT tbl_name from sqlite_master WHERE type = 'table'",values:{}},function(e){if(e.count>0){for(var r=0;r<e.items.length;r++)t.tableList[t.tableList.length]=e.items[r].tbl_name}if(a!=null&&typeof a=="function")a(t.tableList)})};t.dataBase.prototype.createTable=function(e){e.action="create";if(e.success){var t=e.success;e.success=function(e){t(e);this.getTableList()}}var a=this.getQuery(e);this.query(a,e.success,e.fail)};t.dataBase.prototype.dropTable=function(e){e.action="drop";if(e.success){var t=e.success;e.success=function(e){t(e);this.getTableList()}}var a=this.getQuery(e);this.query(a,e.success,e.fail)};t.dataBase.prototype.addRow=function(e){e.action="insert";this.query(this.getQuery(e),e.success,e.fail)};t.dataBase.prototype.getRows=function(e){e.action="select";this.query(this.getQuery(e),e.success,e.fail)};t.dataBase.prototype.updateRows=function(e){e.action="update";var t=this.getQuery(e);this.query(t,e.success,e.fail)};t.dataBase.prototype.deleteRows=function(e){e.action="delete";var t=this.getQuery(e);this.query(t,e.success,e.fail)};t.dataBase.prototype.getQuery=function(e){var t=[];var a=e.filter;var r=e.fields;var s=e.insertFields;var i=e.updateFields;var o=e.tableName;var n="";switch(e.action){case"delete":{n="DELETE FROM "+o.toUpperCase()+" "+this.getFilter(a);t=this.getValues([a]);break}case"update":{n="UPDATE "+o.toUpperCase()+" "+this.getFieldPair(i,"SET ")+" "+this.getFilter(a);t=this.getValues([i,a]);break}case"create":{var f="";if(typeof r=="object"){var u="";for(var l=0;l<r.length;l++){u="";if(typeof r[l]=="object"){if(r[l].name){u=r[l].name;if(r[l].unique&&r[l].unique==true)u+=" unique"}}else if(typeof r[l]=="string"&&r[l].length>0)u=r[l];if(u.length>0){if(f.length>0)f+=","+u.toUpperCase();else f=u.toUpperCase()}}}n="CREATE TABLE IF NOT EXISTS "+o.toUpperCase()+" ("+f+") ";break}case"drop":{n="DROP TABLE IF EXISTS "+o.toUpperCase();break}case"select":{n="SELECT "+this.getValueArrayString(r,"*")+" FROM "+o.toUpperCase()+" "+this.getFilter(a);t=this.getValues([a]);break}case"insert":{t=this.getValues([s]);n="INSERT INTO "+o.toUpperCase()+" ("+this.getKeyString(s)+") VALUES(%values%)";var p="";for(var c=0;c<t.length;c++){if(p.length>0)p+=",?";else p="?"}n=n.replace("%values%",p);break}}return{query:n,values:t}};t.dataBase.prototype.getFieldPair=function(e,t){var a="";var r=t||"";if(typeof e=="object"){var s=0;for(var i in e){var o=(s>0?", ":"")+(i.toUpperCase()+"="+"?");if(a.length==0&&r.length>0)a=r;a+=o;s++}}return a};t.dataBase.prototype.getFilter=function(e){var t="";var a="WHERE ";if(typeof e=="object"){var r=0;for(var s in e){var i="";var o=1;if(typeof e[s]=="object")o=e[s].length;for(var n=0;n<o;n++){i=(n>0?i+" OR ":"(")+(s.toUpperCase()+"="+"?");if(n+1==o)i+=")"}t+=i;r++}}return"WHERE "+t};t.dataBase.prototype.getKeyString=function(e,t){var a="";if(!t)t="";if(typeof e=="array"){for(var r=0;r<valuesItem.length;r++){if(a.length>0)a+=","+valuesItem[r].toUpperCase();else a=valuesItem[r].toUpperCase()}}else if(typeof e=="object"){for(var s in e){if(a.length>0)a+=","+s.toUpperCase();else a=s.toUpperCase()}}if(a.length==0)a=t;return a};t.dataBase.prototype.getValueArrayString=function(e,t){var a="";if(!t)t="";if(typeof e=="object"){for(var r=0;r<e.length;r++){if(a.length>0)a+=","+e[r].toUpperCase();else a=e[r].toUpperCase()}}if(a.length==0)a=t;return a};t.dataBase.prototype.getValues=function(e){var t=[];for(var a=0;a<e.length;a++){var r=e[a];if(typeof r=="object"){for(var s in r){if(typeof r[s]!="object")t[t.length]=r[s];else for(var i=0;i<r[s].length;i++){t[t.length]=r[s][i]}}}else if(typeof r=="array"){for(var i=0;i<r.length;i++){if(typeof r[i]!="object")t[t.length]=r[i]}}}return t};t.dataBase.prototype.query=function(e,t,a){if(!this.dbObject){return}if(typeof t=="undefined"||typeof t!="function")t=function(){};if(typeof a=="undefined"||typeof a!="function")a=function(){};this.dbObject.transaction(function(r){r.executeSql(e.query,e.values,function(e,a){var r={originalResult:a};var s=a.rows.length;if(s>=0){r.count=s;r.items=[];for(var i=0;i<s;i++){var o={};var n=a.rows.item(i);for(var f in n){if(n.hasOwnProperty(f)){o[f]=n[f]}}r.items.push(o)}}if(t!=null)t(r,e)},function(e,t){if(a!=null)a(t,e)})})};t.dataBase.prototype.getResponseObject=function(e){var t=e.rows.length;var a=[];for(var r=0;r<t;r++){a[a.length]=e.rows.item(r)}return a}})(window);
//# sourceMappingURL=core_db.map.js