From a90a757b622cae824dc84636d5a52df16c22179f Mon Sep 17 00:00:00 2001 From: = Date: Wed, 7 Feb 2018 23:16:04 -0500 Subject: [PATCH] improved coverage --- README.md | 2 +- jSQL.js | 9 ++---- jSQL.min.js | 4 +-- package.json | 2 +- src/error_handling/jSQL_Error.js | 4 +-- src/table/jSQLTable.js | 1 - test/test2.js | 47 ++++++++++++++++++++++++++++++-- test/test4.js | 12 ++++++++ 8 files changed, 65 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 58bd14b..204b4fd 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![jSQL Logo](http://i.imgur.com/VQlJKOc.png)](http://pamblam.github.io/jSQL/) -jSQL (Official) - Version 3.2.9 - *Now available without a prescription!* +jSQL (Official) - Version 3.3.5 - *Now available without a prescription!* [![npm version](https://badge.fury.io/js/jsql-official.svg)](https://badge.fury.io/js/jsql-official) [![Build Status](https://travis-ci.org/Pamblam/jSQL.svg?branch=master)](https://travis-ci.org/Pamblam/jSQL) [![Inline docs](http://inch-ci.org/github/Pamblam/jSQL.svg?branch=master)](https://github.com/Pamblam/jSQL/wiki) [![Coverage Status](https://coveralls.io/repos/github/Pamblam/jSQL/badge.svg?branch=master)](https://coveralls.io/github/Pamblam/jSQL?branch=master) diff --git a/jSQL.js b/jSQL.js index 96b8c06..ea152b9 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v3.2.9 + * jsql-official - v3.3.5 * A persistent SQL database. * @author Rob Parham * @website http://pamblam.github.io/jSQL/ @@ -16,10 +16,8 @@ function jSQL_Error(error_no) { this.stack = undefined; var e = new Error(); if(e.stack) this.stack = e.stack; - if(jSQL_Error.message_codes[error_no]) this.message = jSQL_Error.message_codes[error_no]; - else this.message = "Unknown error."; + this.message = jSQL_Error.message_codes[error_no]; this.toString = function () { - if(undefined === this.error) return "jSQL Error - "+this.message; return "jSQL Error #"+this.error+" - "+this.message; }; } @@ -491,7 +489,6 @@ jSQLTable.prototype.initAI = function(auto_increment){ } }; -/* istanbul ignore next */ jSQLTable.prototype.renameColumn = function(oldname, newname){ if(undefined === oldname || "string" !== typeof newname) return _throw(new jSQL_Error("0012")); if(this.columns.indexOf(oldname) < 0) return _throw(new jSQL_Error("0013")); @@ -2816,7 +2813,7 @@ function jsql_import(dump){ } return { - version: "3.2.9", + version: "3.3.5", tables: {}, query: jSQLParseQuery, createTable: createTable, diff --git a/jSQL.min.js b/jSQL.min.js index ac7ed77..c26eaef 100644 --- a/jSQL.min.js +++ b/jSQL.min.js @@ -1,2 +1,2 @@ -/*! jsql-official - v3.2.9 */ -!function(){var isNode=!("undefined"==typeof module||!module.exports),jSQL=function(){"use strict";function jSQL_Error(e){this.error=e,this.stack=void 0;var t=new Error;t.stack&&(this.stack=t.stack),jSQL_Error.message_codes[e]?this.message=jSQL_Error.message_codes[e]:this.message="Unknown error.",this.toString=function(){return void 0===this.error?"jSQL Error - "+this.message:"jSQL Error #"+this.error+" - "+this.message}}function jSQL_Lexer_Error(e,t){var r=t.length>e+25?25:t.length-e,n=t.substr(e,r);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+n+'".',this.stack=void 0;var i=new Error;i.stack&&(this.stack=i.stack),this.toString=function(){return"jSQL Lexer Error #"+this.error+" - "+this.message}}function jSQL_Parse_Error(e,t){this.error="0071",this.message="Unexpected "+e.type+" ("+e.name+") at character "+e.input_pos+".",t&&(this.message+=" Expected "+t+"."),this.stack=void 0;var r=new Error;r.stack&&(this.stack=r.stack),this.toString=function(){return"jSQL Parse Error #"+this.error+" - "+this.message}}jSQL_Error.message_codes={"0001":"Corrupted function stored in data.","0003":"Invalid datatype definition.","0004":"DataType must have a `type` property.","0005":"DataType must have a `serialize` function.","0006":"DataType must have an `unserialize` function.","0007":"Unsupported data type.","0010":"Invalid constraint.","0011":"This table already has a primary key.","0012":"renameColumn expects and old column name and a new one, both must be strings.","0013":"Column does not exist.","0014":"Data must be an array.","0015":"Data not structured properly.","0016":"Cannot insert a null value in a primary column.","0017":"Primary Key violated.","0018":"Cannot insert a null value in a unique column.","0019":"Unique key violated.","0020":"Data type's serialize() method did not return a string.","0021":"Table does not exist.","0022":"Method does not apply to query type.","0023":"Fetch expects paramter one to be 'ASSOC', 'ARRAY', or undefined.","0024":"Expected number or quoted string.","0025":"Expected 'ORDER BY'.","0026":"Must call ORDER BY before using ASC.","0027":"Must call ORDER BY before using DESC.","0028":"Unintelligible query. Expected 'FROM'.","0029":"Unintelligible query. Expected 'TABLE'.","0030":"Unintelligible query. Expected 'INTO'.","0031":"Unintelligible query. Expected 'VALUES'.","0032":"Unintelligible query. Too many values.","0033":"Unintelligible query. Columns mismatch.","0034":"Invalid Column definition.","0035":"Unintelligible query. Expected 'NOT'.","0036":"Unintelligible query. Expected 'EXISTS'.","0037":"Unintelligible query. expected ')'.","0038":"Invalid Arg definition.","0039":"Unintelligible query. Expected 'SET'.","0040":"Unintelligible query. Expected 'FROM'.","0041":"Unintelligible query. WTF?","0042":"Must add a conditional before adding another 'Where' condition.","0043":"Column name must be a string.","0044":"Must add a 'where' clause before the 'equals' call.","0045":"Must add a 'where' clause before the 'preparedLike' call.","0046":"Must add a 'where' clause before the 'doesNotEqual' call.","0047":"Must add a 'where' clause before the 'lessThan' call.","0048":"Must add a 'where' clause before the 'greaterThan' call.","0049":"Must add a 'where' clause before the 'contains' call.","0050":"Must add a 'where' clause before the 'endsWith' call.","0051":"Must add a 'where' clause before the 'beginsWith' call.","0052":"Must use orderBy clause before using ASC.","0053":"Must use orderBy clause before using DESC.","0054":"Could not execute query.","0055":"Error creating table.","0056":"Error opening database.","0057":"indexedDB is not supported in this browser.","0058":"Could not add data after 10 seconds.","0059":"Error updating datastore version.","0060":"Could not connect to the indexedDB datastore.","0061":"Could not initiate a transaction.","0062":"Could not initiate a request.","0063":"Browser doesn't support Web SQL or IndexedDB.","0064":"Unable towrite to datastore file.","0065":"AUTO_INCREMENT column must be a key.","0066":"AUTO_INCREMENT column must be an INT type.","0067":"API is out of memory, cannot store more data.","0068":"Invalid ENUM value.","0069":"NUMERIC or INT type invalid or out of range.","0070":"Unknown Lexer Error.","0071":"Unknown Parser Error.","0072":"Inserting null into a non-null column."};var error_handler_function=function(){},mute_jsql_errors=!1;function _throw(e,t){throw!0!==t&&!0!==mute_jsql_errors&&error_handler_function(e),e}function onError(e){"function"==typeof e&&(error_handler_function=e)}function jSQLDataTypeList(){this.list=[{type:"NUMERIC",aliases:["NUMBER","DECIMAL","FLOAT"],serialize:function(e,t){return null===e&&(e=0),!isNaN(parseFloat(e))&&isFinite(e)?parseFloat(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseFloat(e))&&isFinite(e)?parseFloat(e):_throw(new jSQL_Error("0069"))}},{type:"ENUM",serialize:function(e,t){if(null===e)return"jsqlNull";for(var r=t.length;r--;)if(e===removeQuotes(t[r]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var r=t.length;r--;)if(e===removeQuotes(t[r]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-128&&e<=127?parseInt(e):0},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):0}},{type:"SMALLINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-32768&&e<=32767?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"MEDIUMINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-8388608&&e<=8388607?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"INT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-2147483648&&e<=2147483647?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"BIGINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-9007199254740991&&e<=9007199254740991?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"JSON",aliases:["ARRAY","OBJECT"],serialize:function(e){return null===e?"jsqlNull":"string"==typeof e?e:JSON.stringify(e)},unserialize:function(e){return"jsqlNull"===e?null:JSON.parse(e)}},{type:"FUNCTION",serialize:function(value){if(null===value)return"jsqlNull";if("function"!=typeof value){var f=null;try{eval("f = "+value)}catch(e){}"function"==typeof f?value=f:_throw(new jSQL_Error("0001"))}return"jSQLFunct-"+value.toString()},unserialize:function(value){if("jsqlNull"===value)return null;var p=value.split("-");if("jSQLFunct"!==p.shift())return _throw(new jSQL_Error("0001"));p=value.split("-"),p.shift();var f=null;try{eval("f = "+p.join("-"))}catch(e){}return"function"==typeof f?f:_throw(new jSQL_Error("0001"))}},{type:"BOOLEAN",aliases:["BOOL"],serialize:function(e){return null===e?"jsqlNull":!0===e||"TRUE"==e.toUpperCase()||1==e?"1":"0"},unserialize:function(e){return"jsqlNull"===e?null:!0===e||"TRUE"==e.toUpperCase()||1==e}},{type:"CHAR",serialize:function(e,t){return null===e?"jsqlNull":""+e},unserialize:function(e,t){if("jsqlNull"===e)return null;var r=t[0]>>0,n=" ";return e.length>r?e.substr(0,t[0]):((r-=e.length)>n.length&&(n+=n.repeat(r/n.length)),String(e)+n.slice(0,r))}},{type:"VARCHAR",aliases:["LONGTEXT","MEDIUMTEXT"],serialize:function(e,t){return null===e?"jsqlNull":""+e},unserialize:function(e,t){return"jsqlNull"===e?null:""+e}},{type:"DATE",serialize:function(e){return null===e?"jsqlNull":e instanceof Date?e.getTime():new Date(e).getTime()},unserialize:function(e){return"jsqlNull"===e?null:new Date(e)}},{type:"AMBI",serialize:function(e){return null===e?"jsqlNull":e instanceof Date?e.getTime():"function"==typeof e?"jSQLFunct-"+e.toString():!isNaN(parseFloat(e))&&isFinite(e)?e:""+e},unserialize:function(value){if("jsqlNull"===value)return null;if("string"==typeof value&&"jSQLFunct"===value.split("-")[0]){var p=value.split("-");p.shift();var f=null;try{eval("f = "+p.join("-"))}catch(e){}if("function"==typeof f)return f}return value}}],this.add=function(e){return"object"!=typeof e?_throw(new jSQL_Error("0003")):void 0===e.type?_throw(new jSQL_Error("0004")):"function"!=typeof e.serialize?_throw(new jSQL_Error("0005")):"function"!=typeof e.unserialize?_throw(new jSQL_Error("0006")):void this.list.push({type:e.type.toUpperCase(),aliases:Array.isArray(e.aliases)?e.aliases:[],serialize:e.serialize,unserialize:e.unserialize})},this.exists=function(e){e=e.toUpperCase();for(var t=this.list.length;t--;)if(this.list[t].type===e||void 0!==this.list[t].aliases&&this.list[t].aliases.indexOf(e)>-1)return!0;return!1},this.getByType=function(e){e=e.toUpperCase();for(var t=this.list.length;t--;)if(this.list[t].type===e||void 0!==this.list[t].aliases&&this.list[t].aliases.indexOf(e)>-1)return this.list[t];return _throw(new jSQL_Error("0007"))}}function jSQLTable(e,t,r,n,i,a){var s=this;if(s.name="",s.columns=[],s.data=[],s.colmap={},s.types=[],s.auto_inc_col=!1,s.auto_inc_seq=0,s.keys={primary:{column:!1,map:{}},unique:[]},s.name=e,void 0===n&&(n=[]),Array.isArray(t)&&void 0===r&&(r=t,t=[]),Array.isArray(t)&&!Array.isArray(t[0])&&"object"==typeof t[0]){var o,u=[];for(o in t[0])t[0].hasOwnProperty(o)&&u.push(o);r=t,t=u}s.initColumns(t,n),s.initKeys(i,a),s.initAI(a),void 0!==r&&s.loadData(r)}function jSQLQuery(e){var t=this;t.type=e.toUpperCase(),t.tablename=null,t.columns=[],t.data=[],t.INEFlag=!1,t.coltypes=[],t.table=null,t.newvals={},t.whereClause=new jSQLWhereClause(t),t.resultSet=[];for(var r=["init","ifNotExists","execute","fetch","ignore","fetchAll","values","set","where","from","orderBy","asc","desc","limit","distinct"],n={CREATE:jSQLCreateQuery,UPDATE:jSQLUpdateQuery,SELECT:jSQLSelectQuery,INSERT:jSQLInsertQuery,DROP:jSQLDropQuery,DELETE:jSQLDeleteQuery},i=0;i-1?delete this.table.keys.primary.map[o]:this.table.keys.primary.map[o]=r.length)}for(var c=0;i=this.table.keys.unique[c];c++){for(var f,p=Array.isArray(i.column)?i.column:[i.column],y=[],m=0;f=p[m];m++){var S=this.table.colmap[f];if(null===a[S])return _throw(new jSQL_Error("0018"));y.push(a[S])}if(y=JSON.stringify(y),i.map.hasOwnProperty(y)&&i.map[y]==n){if(!0===this.ignoreFlag)return this;e.indexOf(n)>-1?delete this.table.keys.unique[c].map[y]:this.table.keys.unique[c].map[y]=r.length}}e.indexOf(n)>-1?t.push(a):r.push(this.table.data[n])}return this.table.data=r,this.resultSet=t,this},this.where=function(e){return this.whereClause.where(e)},this.fetch=function(){return null},this.fetchAll=function(){return[]},this.orderBy=function(e){return this.whereClause.orderBy(e)},this.asc=function(){return this.whereClause.asc()},this.desc=function(){return this.whereClause.desc()},this.limit=function(){return this.whereClause.limit()},this.distinct=function(){return this.whereClause.isDistinct=!0,this}}function jSQLDropQuery(){this.init=function(e){return this.tablename=e,this},this.execute=function(){return void 0===jSQL.tables[this.tablename]?_throw(new jSQL_Error("0021")):(delete jSQL.tables[this.tablename],this)},this.fetch=function(){return null},this.fetchAll=function(){return[]}}function jSQLInsertQuery(){this.init=function(e){return this.table=e,this.ignoreFlag=!1,this},this.values=function(e){return void 0===jSQL.tables[this.table]?_throw(new jSQL_Error("0021")):(this.data=e,this)},this.execute=function(e){if(void 0!==e&&Array.isArray(e)&&e.length>0)if(Array.isArray(this.data))for(var t=this.data.length;t--&&e.length;)"?"==this.data[t]&&(this.data[t]=e.shift());else for(var t in this.data)this.data.hasOwnProperty(t)&&e.length&&"?"==this.data[t]&&(this.data[t]=e.shift());return jSQL.tables[this.table].insertRow(this.data,this.ignoreFlag),this},this.ignore=function(){return this.ignoreFlag=!0,this},this.fetch=function(){return null},this.fetchAll=function(){return[]}}function jSQLSelectQuery(){this.init=function(e){return this.columns=Array.isArray(e)?e:[e],this},this.from=function(e){return void 0===jSQL.tables[e]?_throw(new jSQL_Error("0021")):(this.table=jSQL.tables[e],"*"==this.columns[0]&&(this.columns=this.table.columns),this)},this.where=function(e){return this.whereClause.where(e)},this.execute=function(){for(var e=this.whereClause.getResultRowIndexes(),t=[],r=0;r0;)t.push(this.fetch(e));return t},this.orderBy=function(e){return this.whereClause.orderBy(e)},this.asc=function(){return this.whereClause.asc()},this.desc=function(){return this.whereClause.desc()},this.limit=function(){return this.whereClause.limit()},this.distinct=function(){return this.whereClause.isDistinct=!0,this}}function jSQLUpdateQuery(){this.init=function(e){return void 0===jSQL.tables[e]?_throw(new jSQL_Error("0021")):(this.table=this.table=jSQL.tables[e],this.ignoreFlag=!1,this)},this.set=function(e){for(var t in this.newvals=e,e)e.hasOwnProperty(t)&&this.columns.push(t);return this},this.where=function(e){return this.whereClause.where(e)},this.execute=function(e){if(void 0!==e&&Array.isArray(e))for(var t in this.newvals)this.newvals.hasOwnProperty(t)&&"?"==this.newvals[t]&&e.length&&(this.newvals[t]=e.shift());var r=this.whereClause.getResultRowIndexes(),n=[],i=[];for(t=0;t=this.table.auto_inc_seq&&(this.table.auto_inc_seq=this.newvals[this.columns[o]]+1)),s[this.table.colmap[this.columns[o]]]=this.table.normalizeColumnStoreValue(this.columns[o],this.newvals[this.columns[o]]);var u=this.table.keys.primary.column,l=!1;if(!1!==u){var h;Array.isArray(u)||(u=[u]),l=[];for(var c=0;h=u[c];c++){var f=this.table.colmap[h];if(null===s[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));l.push(s[f])}if(l=JSON.stringify(l),this.table.keys.primary.map.hasOwnProperty(l)&&this.table.keys.primary.map[l]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var p,y=[],m=0;p=this.table.keys.unique[m];m++){for(var S=Array.isArray(p.column)?p.column:[p.column],d=[],E=0;g=S[E];E++){var L=this.table.colmap[g];if(null===s[L])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));d.push(s[L])}if(d=JSON.stringify(d),p.map.hasOwnProperty(d)&&p.map[d]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(d)}i.push({rowIndex:a,row:s,pk_vals:l,uni_vals:y})}for(t=0;t",value:e}),t.pendingColumn="",t)},t.contains=function(e){return""==t.pendingColumn?_throw(new jSQL_Error("0049")):(t.conditions.push({col:t.pendingColumn,type:"%%",value:e}),t.pendingColumn="",t)},t.endsWith=function(e){return""==t.pendingColumn?_throw(new jSQL_Error("0050")):(t.conditions.push({col:t.pendingColumn,type:"%-",value:e}),t.pendingColumn="",t)},t.beginsWith=function(e){return""==t.pendingColumn?_throw(new jSQL_Error("0051")):(t.conditions.push({col:t.pendingColumn,type:"-%",value:e}),t.pendingColumn="",t)},t.and=function(e){return t.where(e)},t.or=function(e){return t.finalConditions.push(t.conditions),t.conditions=[],t.where(e)},t.limit=function(e,r){return t.LIMIT=parseInt(e),void 0!==r&&(t.OFFSET=parseInt(r)),t},t.orderBy=function(e){return Array.isArray(e)||(e=[e]),t.sortColumn=e,t},t.asc=function(){return""==t.sortColumn?_throw(new jSQL_Error("0052")):(t.sortDirection="ASC",t)},t.desc=function(){return""==t.sortColumn?_throw(new jSQL_Error("0053")):(t.sortDirection="DESC",t)},t.execute=function(e){if(void 0===e&&(e=[]),t.conditions.length>0&&t.finalConditions.push(t.conditions),e.length>0)for(var r=t.finalConditions.length;r--;)for(var n=t.finalConditions[r].length;n--;)if("?"===t.finalConditions[r][n].value&&"pl"===t.finalConditions[r][n].type){var i=e.pop();"%"==i.substr(0,1)&&"%"==i.substr(i.length-1,1)?(t.finalConditions[r][n].value=i.substr(1,i.length-2),t.finalConditions[r][n].type="%%"):"%"==i.substr(0,1)?(t.finalConditions[r][n].value=i.substr(1,i.length-1),t.finalConditions[r][n].type="%-"):"%"==i.substr(i.length-1,1)?(t.finalConditions[r][n].value=i.substr(0,i.length-1),t.finalConditions[r][n].type="-%"):(t.finalConditions[r][n].value=i,t.finalConditions[r][n].type="=")}else"?"===t.finalConditions[r][n].value&&e.length>0&&(t.finalConditions[r][n].value=e.pop());return t.context.execute(e)},t.fetch=function(e){return t.context.fetch(e)},t.fetchAll=function(e){return t.context.fetchAll(e)},t.getResultRowIndexes=function(){for(var e=[],r=0;r":(isNaN(parseFloat(h))||h<=u.value)&&(s=!1);break;case"<":(isNaN(parseFloat(h))||h>=u.value)&&(s=!1);break;case"=":h!=u.value&&(s=!1);break;case"!=":break;case"%%":h.indexOf(u.value)<0&&(s=!1);break;case"%-":h.indexOf(u.value)!=h.length-u.value.length&&(s=!1);break;case"-%":0!=h.indexOf(u.value)&&(s=!1)}if(!s)break}if(s){n=!0;break}}n&&e.push(r)}if(t.sortColumn.length>0&&(e.sort(function(e,r){return e=t.context.table.data[e],r=t.context.table.data[r],function n(i){if(void 0===t.sortColumn[i])return 0;var a=t.sortColumn[i],s=t.context.table.colmap[a];return e[s]r[s]?1:n(i+1)}(0)}),"DESC"==t.sortDirection&&e.reverse()),t.isDistinct){var c=[];for(r=0;r-1||(p.push(e[r]),f.push(S))}e=p}return t.LIMIT>0&&e.length>t.LIMIT&&(t.OFFSET>e.length&&(e=[]),t.LIMIT>e.length&&(t.LIMIT=e.length),e.length&&(e=e.slice(t.OFFSET,t.OFFSET+t.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var r;for(this.columns=e,r=0;r-1,r=this.keys.primary.column===e,n=!1,i=this.keys.unique.length;i--;){var a=Array.isArray(this.keys.unique[i].column)&&this.keys.unique[i].column.indexOf(e)>-1,s=this.keys.unique[i].column===e;(a||s)&&(n=!0)}if(!(t||r||n))return _throw(new jSQL_Error("0065"));if("INT"!==this.types[this.colmap[e]].type)return _throw(new jSQL_Error("0066"));this.auto_inc_col=e}},jSQLTable.prototype.renameColumn=function(e,t){if(void 0===e||"string"!=typeof t)return _throw(new jSQL_Error("0012"));if(this.columns.indexOf(e)<0)return _throw(new jSQL_Error("0013"));if(this.columns.splice(this.columns.indexOf(e),1,t),this.keys.primary.column===e&&(this.keys.primary.column=t),Array.isArray(this.keys.primary.column))for(var r=this.keys.primary.column.length;r--;)this.keys.primary.column[r]===e&&(this.keys.primary.column[r]=t);for(var n=this.keys.unique.length;n--;)if(this.keys.unique[n].column===e&&(this.keys.unique[n].column=t),Array.isArray(this.keys.unique[n].column))for(r=this.keys.unique[n].column.length;r--;)this.keys.unique[n].column[r]===e&&(this.keys.unique[n].column[r]=t);var i={};for(var a in this.colmap)this.colmap.hasOwnProperty(a)&&(a===e?i[t]=this.colmap[a]:i[a]=this.colmap[a]);this.colmap=i,this.auto_inc_col===e&&(this.auto_inc_col=t)},jSQLTable.prototype.addColumn=function(e,t,r){if(void 0!==r&&void 0!==r.type||(r={type:"AMBI",args:[],null:!0,default:void 0}),r.type=r.type.toUpperCase(),void 0===t&&(t=null),"string"!=typeof e){var n=this;e=function e(t){for(var r=0;rthis.columns.length;)this.addColumn();for(;e.length-1){this.renameColumn("u0",i);for(;this.columns.indexOf("u1")>-1;)this.renameColumn("u1","u0")}else this.addColumn(i);for(t=0;t=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(r[n],10)+1)),r[n]=this.normalizeColumnStoreValue(this.columns[n],r[n]);if(!1===this.updateKeysOnInsert(r,t))return!1;this.data.push(r)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var r,n=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a-1&&null===t)return _throw(new jSQL_Error("0072"));null===t&&void 0!==r.default&&(t=r.default);var n=jSQL.types.getByType(r.type.toUpperCase()).serialize(t,r.args);return!isNaN(parseFloat(n))&&isFinite(n)||"string"==typeof n?n:_throw(new jSQL_Error("0020"))},jSQLTable.prototype.normalizeColumnFetchValue=function(e,t){var r=this.types[this.colmap[e]];return jSQL.types.getByType(r.type.toUpperCase()).unserialize(t,r.args)},jSQLLexer.prototype.getNextToken=function(){for(var e,t=0;t/gi,type:"SYMBOL",name:"NOT EQUAL"},{pattern:/\(/gi,type:"SYMBOL",name:"LEFT PEREN"},{pattern:/\)/gi,type:"SYMBOL",name:"RIGHT PEREN"},{pattern:/,/gi,type:"SYMBOL",name:"COMMA"},{pattern:/\?/gi,type:"SYMBOL",name:"QUESTION MARK"},{pattern:/,/gi,type:"SYMBOL",name:"COMMA"},{pattern:/\*/gi,type:"SYMBOL",name:"ASTERISK"},{pattern:/;/gi,type:"SYMBOL",name:"SEMICOLON"},{pattern:/=/gi,type:"SYMBOL",name:"EQUALS"},{pattern:/>/gi,type:"SYMBOL",name:"GREATER THAN"},{pattern:/500){for(mute_jsql_errors=!1,e.isLoading=!1,e.loaded=!0;e.loadingCallbacks.length;)e.loadingCallbacks.shift()();return}setTimeout(function(){r(n+1)},10)}}(0)},e.init=function(t){if("function"!=typeof t&&(t=function(){}),e.initiated=!0,isNode)e.api=new API.nodeAPI,e.api.init([{name:"jSQL_data_schema",rows:[]}],t);else{var r=e.api_user_priority.concat(e.api_default_priority),n=[],i=!1;!function a(s){if(s>=r.length&&!i)return _throw(new jSQL_Error("0063"));if(-1===e.api_default_priority.indexOf(r[s]))return a(1+s);if(n.indexOf(r[s])>-1)return a(1+s);try{e.api=new API[r[s]],e.api.init([{name:"jSQL_data_schema",rows:[]}],t),i=!0}catch(e){i=!1}i||a(1+s)}(0)}}};function createTable(e,t,r,n,i){var a=void 0===t&&void 0===r&&"object"==typeof e&&void 0===n,s=Array.isArray(t)&&void 0===r&&"object"==typeof e&&void 0===n;if(a||s)for(var o in s&&(n=void 0===t?[]:t),void 0===n&&(n=[]),t=[],r=[],e)if(e.hasOwnProperty(o)){var u=e[o];e=o;for(var l=0;le+25?25:t.length-e,n=t.substr(e,r);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+n+'".',this.stack=void 0;var i=new Error;i.stack&&(this.stack=i.stack),this.toString=function(){return"jSQL Lexer Error #"+this.error+" - "+this.message}}function jSQL_Parse_Error(e,t){this.error="0071",this.message="Unexpected "+e.type+" ("+e.name+") at character "+e.input_pos+".",t&&(this.message+=" Expected "+t+"."),this.stack=void 0;var r=new Error;r.stack&&(this.stack=r.stack),this.toString=function(){return"jSQL Parse Error #"+this.error+" - "+this.message}}jSQL_Error.message_codes={"0001":"Corrupted function stored in data.","0003":"Invalid datatype definition.","0004":"DataType must have a `type` property.","0005":"DataType must have a `serialize` function.","0006":"DataType must have an `unserialize` function.","0007":"Unsupported data type.","0010":"Invalid constraint.","0011":"This table already has a primary key.","0012":"renameColumn expects and old column name and a new one, both must be strings.","0013":"Column does not exist.","0014":"Data must be an array.","0015":"Data not structured properly.","0016":"Cannot insert a null value in a primary column.","0017":"Primary Key violated.","0018":"Cannot insert a null value in a unique column.","0019":"Unique key violated.","0020":"Data type's serialize() method did not return a string.","0021":"Table does not exist.","0022":"Method does not apply to query type.","0023":"Fetch expects paramter one to be 'ASSOC', 'ARRAY', or undefined.","0024":"Expected number or quoted string.","0025":"Expected 'ORDER BY'.","0026":"Must call ORDER BY before using ASC.","0027":"Must call ORDER BY before using DESC.","0028":"Unintelligible query. Expected 'FROM'.","0029":"Unintelligible query. Expected 'TABLE'.","0030":"Unintelligible query. Expected 'INTO'.","0031":"Unintelligible query. Expected 'VALUES'.","0032":"Unintelligible query. Too many values.","0033":"Unintelligible query. Columns mismatch.","0034":"Invalid Column definition.","0035":"Unintelligible query. Expected 'NOT'.","0036":"Unintelligible query. Expected 'EXISTS'.","0037":"Unintelligible query. expected ')'.","0038":"Invalid Arg definition.","0039":"Unintelligible query. Expected 'SET'.","0040":"Unintelligible query. Expected 'FROM'.","0041":"Unintelligible query. WTF?","0042":"Must add a conditional before adding another 'Where' condition.","0043":"Column name must be a string.","0044":"Must add a 'where' clause before the 'equals' call.","0045":"Must add a 'where' clause before the 'preparedLike' call.","0046":"Must add a 'where' clause before the 'doesNotEqual' call.","0047":"Must add a 'where' clause before the 'lessThan' call.","0048":"Must add a 'where' clause before the 'greaterThan' call.","0049":"Must add a 'where' clause before the 'contains' call.","0050":"Must add a 'where' clause before the 'endsWith' call.","0051":"Must add a 'where' clause before the 'beginsWith' call.","0052":"Must use orderBy clause before using ASC.","0053":"Must use orderBy clause before using DESC.","0054":"Could not execute query.","0055":"Error creating table.","0056":"Error opening database.","0057":"indexedDB is not supported in this browser.","0058":"Could not add data after 10 seconds.","0059":"Error updating datastore version.","0060":"Could not connect to the indexedDB datastore.","0061":"Could not initiate a transaction.","0062":"Could not initiate a request.","0063":"Browser doesn't support Web SQL or IndexedDB.","0064":"Unable towrite to datastore file.","0065":"AUTO_INCREMENT column must be a key.","0066":"AUTO_INCREMENT column must be an INT type.","0067":"API is out of memory, cannot store more data.","0068":"Invalid ENUM value.","0069":"NUMERIC or INT type invalid or out of range.","0070":"Unknown Lexer Error.","0071":"Unknown Parser Error.","0072":"Inserting null into a non-null column."};var error_handler_function=function(){},mute_jsql_errors=!1;function _throw(e,t){throw!0!==t&&!0!==mute_jsql_errors&&error_handler_function(e),e}function onError(e){"function"==typeof e&&(error_handler_function=e)}function jSQLDataTypeList(){this.list=[{type:"NUMERIC",aliases:["NUMBER","DECIMAL","FLOAT"],serialize:function(e,t){return null===e&&(e=0),!isNaN(parseFloat(e))&&isFinite(e)?parseFloat(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseFloat(e))&&isFinite(e)?parseFloat(e):_throw(new jSQL_Error("0069"))}},{type:"ENUM",serialize:function(e,t){if(null===e)return"jsqlNull";for(var r=t.length;r--;)if(e===removeQuotes(t[r]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var r=t.length;r--;)if(e===removeQuotes(t[r]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-128&&e<=127?parseInt(e):0},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):0}},{type:"SMALLINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-32768&&e<=32767?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"MEDIUMINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-8388608&&e<=8388607?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"INT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-2147483648&&e<=2147483647?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"BIGINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&e>=-9007199254740991&&e<=9007199254740991?parseInt(e):_throw(new jSQL_Error("0069"))},unserialize:function(e,t){return e||(e=0),!isNaN(parseInt(e))&&isFinite(e)?parseInt(e):_throw(new jSQL_Error("0069"))}},{type:"JSON",aliases:["ARRAY","OBJECT"],serialize:function(e){return null===e?"jsqlNull":"string"==typeof e?e:JSON.stringify(e)},unserialize:function(e){return"jsqlNull"===e?null:JSON.parse(e)}},{type:"FUNCTION",serialize:function(value){if(null===value)return"jsqlNull";if("function"!=typeof value){var f=null;try{eval("f = "+value)}catch(e){}"function"==typeof f?value=f:_throw(new jSQL_Error("0001"))}return"jSQLFunct-"+value.toString()},unserialize:function(value){if("jsqlNull"===value)return null;var p=value.split("-");if("jSQLFunct"!==p.shift())return _throw(new jSQL_Error("0001"));p=value.split("-"),p.shift();var f=null;try{eval("f = "+p.join("-"))}catch(e){}return"function"==typeof f?f:_throw(new jSQL_Error("0001"))}},{type:"BOOLEAN",aliases:["BOOL"],serialize:function(e){return null===e?"jsqlNull":!0===e||"TRUE"==e.toUpperCase()||1==e?"1":"0"},unserialize:function(e){return"jsqlNull"===e?null:!0===e||"TRUE"==e.toUpperCase()||1==e}},{type:"CHAR",serialize:function(e,t){return null===e?"jsqlNull":""+e},unserialize:function(e,t){if("jsqlNull"===e)return null;var r=t[0]>>0,n=" ";return e.length>r?e.substr(0,t[0]):((r-=e.length)>n.length&&(n+=n.repeat(r/n.length)),String(e)+n.slice(0,r))}},{type:"VARCHAR",aliases:["LONGTEXT","MEDIUMTEXT"],serialize:function(e,t){return null===e?"jsqlNull":""+e},unserialize:function(e,t){return"jsqlNull"===e?null:""+e}},{type:"DATE",serialize:function(e){return null===e?"jsqlNull":e instanceof Date?e.getTime():new Date(e).getTime()},unserialize:function(e){return"jsqlNull"===e?null:new Date(e)}},{type:"AMBI",serialize:function(e){return null===e?"jsqlNull":e instanceof Date?e.getTime():"function"==typeof e?"jSQLFunct-"+e.toString():!isNaN(parseFloat(e))&&isFinite(e)?e:""+e},unserialize:function(value){if("jsqlNull"===value)return null;if("string"==typeof value&&"jSQLFunct"===value.split("-")[0]){var p=value.split("-");p.shift();var f=null;try{eval("f = "+p.join("-"))}catch(e){}if("function"==typeof f)return f}return value}}],this.add=function(e){return"object"!=typeof e?_throw(new jSQL_Error("0003")):void 0===e.type?_throw(new jSQL_Error("0004")):"function"!=typeof e.serialize?_throw(new jSQL_Error("0005")):"function"!=typeof e.unserialize?_throw(new jSQL_Error("0006")):void this.list.push({type:e.type.toUpperCase(),aliases:Array.isArray(e.aliases)?e.aliases:[],serialize:e.serialize,unserialize:e.unserialize})},this.exists=function(e){e=e.toUpperCase();for(var t=this.list.length;t--;)if(this.list[t].type===e||void 0!==this.list[t].aliases&&this.list[t].aliases.indexOf(e)>-1)return!0;return!1},this.getByType=function(e){e=e.toUpperCase();for(var t=this.list.length;t--;)if(this.list[t].type===e||void 0!==this.list[t].aliases&&this.list[t].aliases.indexOf(e)>-1)return this.list[t];return _throw(new jSQL_Error("0007"))}}function jSQLTable(e,t,r,n,i,a){var s=this;if(s.name="",s.columns=[],s.data=[],s.colmap={},s.types=[],s.auto_inc_col=!1,s.auto_inc_seq=0,s.keys={primary:{column:!1,map:{}},unique:[]},s.name=e,void 0===n&&(n=[]),Array.isArray(t)&&void 0===r&&(r=t,t=[]),Array.isArray(t)&&!Array.isArray(t[0])&&"object"==typeof t[0]){var o,u=[];for(o in t[0])t[0].hasOwnProperty(o)&&u.push(o);r=t,t=u}s.initColumns(t,n),s.initKeys(i,a),s.initAI(a),void 0!==r&&s.loadData(r)}function jSQLQuery(e){var t=this;t.type=e.toUpperCase(),t.tablename=null,t.columns=[],t.data=[],t.INEFlag=!1,t.coltypes=[],t.table=null,t.newvals={},t.whereClause=new jSQLWhereClause(t),t.resultSet=[];for(var r=["init","ifNotExists","execute","fetch","ignore","fetchAll","values","set","where","from","orderBy","asc","desc","limit","distinct"],n={CREATE:jSQLCreateQuery,UPDATE:jSQLUpdateQuery,SELECT:jSQLSelectQuery,INSERT:jSQLInsertQuery,DROP:jSQLDropQuery,DELETE:jSQLDeleteQuery},i=0;i-1?delete this.table.keys.primary.map[o]:this.table.keys.primary.map[o]=r.length)}for(var c=0;i=this.table.keys.unique[c];c++){for(var f,p=Array.isArray(i.column)?i.column:[i.column],y=[],m=0;f=p[m];m++){var S=this.table.colmap[f];if(null===a[S])return _throw(new jSQL_Error("0018"));y.push(a[S])}if(y=JSON.stringify(y),i.map.hasOwnProperty(y)&&i.map[y]==n){if(!0===this.ignoreFlag)return this;e.indexOf(n)>-1?delete this.table.keys.unique[c].map[y]:this.table.keys.unique[c].map[y]=r.length}}e.indexOf(n)>-1?t.push(a):r.push(this.table.data[n])}return this.table.data=r,this.resultSet=t,this},this.where=function(e){return this.whereClause.where(e)},this.fetch=function(){return null},this.fetchAll=function(){return[]},this.orderBy=function(e){return this.whereClause.orderBy(e)},this.asc=function(){return this.whereClause.asc()},this.desc=function(){return this.whereClause.desc()},this.limit=function(){return this.whereClause.limit()},this.distinct=function(){return this.whereClause.isDistinct=!0,this}}function jSQLDropQuery(){this.init=function(e){return this.tablename=e,this},this.execute=function(){return void 0===jSQL.tables[this.tablename]?_throw(new jSQL_Error("0021")):(delete jSQL.tables[this.tablename],this)},this.fetch=function(){return null},this.fetchAll=function(){return[]}}function jSQLInsertQuery(){this.init=function(e){return this.table=e,this.ignoreFlag=!1,this},this.values=function(e){return void 0===jSQL.tables[this.table]?_throw(new jSQL_Error("0021")):(this.data=e,this)},this.execute=function(e){if(void 0!==e&&Array.isArray(e)&&e.length>0)if(Array.isArray(this.data))for(var t=this.data.length;t--&&e.length;)"?"==this.data[t]&&(this.data[t]=e.shift());else for(var t in this.data)this.data.hasOwnProperty(t)&&e.length&&"?"==this.data[t]&&(this.data[t]=e.shift());return jSQL.tables[this.table].insertRow(this.data,this.ignoreFlag),this},this.ignore=function(){return this.ignoreFlag=!0,this},this.fetch=function(){return null},this.fetchAll=function(){return[]}}function jSQLSelectQuery(){this.init=function(e){return this.columns=Array.isArray(e)?e:[e],this},this.from=function(e){return void 0===jSQL.tables[e]?_throw(new jSQL_Error("0021")):(this.table=jSQL.tables[e],"*"==this.columns[0]&&(this.columns=this.table.columns),this)},this.where=function(e){return this.whereClause.where(e)},this.execute=function(){for(var e=this.whereClause.getResultRowIndexes(),t=[],r=0;r0;)t.push(this.fetch(e));return t},this.orderBy=function(e){return this.whereClause.orderBy(e)},this.asc=function(){return this.whereClause.asc()},this.desc=function(){return this.whereClause.desc()},this.limit=function(){return this.whereClause.limit()},this.distinct=function(){return this.whereClause.isDistinct=!0,this}}function jSQLUpdateQuery(){this.init=function(e){return void 0===jSQL.tables[e]?_throw(new jSQL_Error("0021")):(this.table=this.table=jSQL.tables[e],this.ignoreFlag=!1,this)},this.set=function(e){for(var t in this.newvals=e,e)e.hasOwnProperty(t)&&this.columns.push(t);return this},this.where=function(e){return this.whereClause.where(e)},this.execute=function(e){if(void 0!==e&&Array.isArray(e))for(var t in this.newvals)this.newvals.hasOwnProperty(t)&&"?"==this.newvals[t]&&e.length&&(this.newvals[t]=e.shift());var r=this.whereClause.getResultRowIndexes(),n=[],i=[];for(t=0;t=this.table.auto_inc_seq&&(this.table.auto_inc_seq=this.newvals[this.columns[o]]+1)),s[this.table.colmap[this.columns[o]]]=this.table.normalizeColumnStoreValue(this.columns[o],this.newvals[this.columns[o]]);var u=this.table.keys.primary.column,l=!1;if(!1!==u){var h;Array.isArray(u)||(u=[u]),l=[];for(var c=0;h=u[c];c++){var f=this.table.colmap[h];if(null===s[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));l.push(s[f])}if(l=JSON.stringify(l),this.table.keys.primary.map.hasOwnProperty(l)&&this.table.keys.primary.map[l]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var p,y=[],m=0;p=this.table.keys.unique[m];m++){for(var S=Array.isArray(p.column)?p.column:[p.column],d=[],E=0;g=S[E];E++){var L=this.table.colmap[g];if(null===s[L])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));d.push(s[L])}if(d=JSON.stringify(d),p.map.hasOwnProperty(d)&&p.map[d]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(d)}i.push({rowIndex:a,row:s,pk_vals:l,uni_vals:y})}for(t=0;t",value:e}),t.pendingColumn="",t)},t.contains=function(e){return""==t.pendingColumn?_throw(new jSQL_Error("0049")):(t.conditions.push({col:t.pendingColumn,type:"%%",value:e}),t.pendingColumn="",t)},t.endsWith=function(e){return""==t.pendingColumn?_throw(new jSQL_Error("0050")):(t.conditions.push({col:t.pendingColumn,type:"%-",value:e}),t.pendingColumn="",t)},t.beginsWith=function(e){return""==t.pendingColumn?_throw(new jSQL_Error("0051")):(t.conditions.push({col:t.pendingColumn,type:"-%",value:e}),t.pendingColumn="",t)},t.and=function(e){return t.where(e)},t.or=function(e){return t.finalConditions.push(t.conditions),t.conditions=[],t.where(e)},t.limit=function(e,r){return t.LIMIT=parseInt(e),void 0!==r&&(t.OFFSET=parseInt(r)),t},t.orderBy=function(e){return Array.isArray(e)||(e=[e]),t.sortColumn=e,t},t.asc=function(){return""==t.sortColumn?_throw(new jSQL_Error("0052")):(t.sortDirection="ASC",t)},t.desc=function(){return""==t.sortColumn?_throw(new jSQL_Error("0053")):(t.sortDirection="DESC",t)},t.execute=function(e){if(void 0===e&&(e=[]),t.conditions.length>0&&t.finalConditions.push(t.conditions),e.length>0)for(var r=t.finalConditions.length;r--;)for(var n=t.finalConditions[r].length;n--;)if("?"===t.finalConditions[r][n].value&&"pl"===t.finalConditions[r][n].type){var i=e.pop();"%"==i.substr(0,1)&&"%"==i.substr(i.length-1,1)?(t.finalConditions[r][n].value=i.substr(1,i.length-2),t.finalConditions[r][n].type="%%"):"%"==i.substr(0,1)?(t.finalConditions[r][n].value=i.substr(1,i.length-1),t.finalConditions[r][n].type="%-"):"%"==i.substr(i.length-1,1)?(t.finalConditions[r][n].value=i.substr(0,i.length-1),t.finalConditions[r][n].type="-%"):(t.finalConditions[r][n].value=i,t.finalConditions[r][n].type="=")}else"?"===t.finalConditions[r][n].value&&e.length>0&&(t.finalConditions[r][n].value=e.pop());return t.context.execute(e)},t.fetch=function(e){return t.context.fetch(e)},t.fetchAll=function(e){return t.context.fetchAll(e)},t.getResultRowIndexes=function(){for(var e=[],r=0;r":(isNaN(parseFloat(h))||h<=u.value)&&(s=!1);break;case"<":(isNaN(parseFloat(h))||h>=u.value)&&(s=!1);break;case"=":h!=u.value&&(s=!1);break;case"!=":break;case"%%":h.indexOf(u.value)<0&&(s=!1);break;case"%-":h.indexOf(u.value)!=h.length-u.value.length&&(s=!1);break;case"-%":0!=h.indexOf(u.value)&&(s=!1)}if(!s)break}if(s){n=!0;break}}n&&e.push(r)}if(t.sortColumn.length>0&&(e.sort(function(e,r){return e=t.context.table.data[e],r=t.context.table.data[r],function n(i){if(void 0===t.sortColumn[i])return 0;var a=t.sortColumn[i],s=t.context.table.colmap[a];return e[s]r[s]?1:n(i+1)}(0)}),"DESC"==t.sortDirection&&e.reverse()),t.isDistinct){var c=[];for(r=0;r-1||(p.push(e[r]),f.push(S))}e=p}return t.LIMIT>0&&e.length>t.LIMIT&&(t.OFFSET>e.length&&(e=[]),t.LIMIT>e.length&&(t.LIMIT=e.length),e.length&&(e=e.slice(t.OFFSET,t.OFFSET+t.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var r;for(this.columns=e,r=0;r-1,r=this.keys.primary.column===e,n=!1,i=this.keys.unique.length;i--;){var a=Array.isArray(this.keys.unique[i].column)&&this.keys.unique[i].column.indexOf(e)>-1,s=this.keys.unique[i].column===e;(a||s)&&(n=!0)}if(!(t||r||n))return _throw(new jSQL_Error("0065"));if("INT"!==this.types[this.colmap[e]].type)return _throw(new jSQL_Error("0066"));this.auto_inc_col=e}},jSQLTable.prototype.renameColumn=function(e,t){if(void 0===e||"string"!=typeof t)return _throw(new jSQL_Error("0012"));if(this.columns.indexOf(e)<0)return _throw(new jSQL_Error("0013"));if(this.columns.splice(this.columns.indexOf(e),1,t),this.keys.primary.column===e&&(this.keys.primary.column=t),Array.isArray(this.keys.primary.column))for(var r=this.keys.primary.column.length;r--;)this.keys.primary.column[r]===e&&(this.keys.primary.column[r]=t);for(var n=this.keys.unique.length;n--;)if(this.keys.unique[n].column===e&&(this.keys.unique[n].column=t),Array.isArray(this.keys.unique[n].column))for(r=this.keys.unique[n].column.length;r--;)this.keys.unique[n].column[r]===e&&(this.keys.unique[n].column[r]=t);var i={};for(var a in this.colmap)this.colmap.hasOwnProperty(a)&&(a===e?i[t]=this.colmap[a]:i[a]=this.colmap[a]);this.colmap=i,this.auto_inc_col===e&&(this.auto_inc_col=t)},jSQLTable.prototype.addColumn=function(e,t,r){if(void 0!==r&&void 0!==r.type||(r={type:"AMBI",args:[],null:!0,default:void 0}),r.type=r.type.toUpperCase(),void 0===t&&(t=null),"string"!=typeof e){var n=this;e=function e(t){for(var r=0;rthis.columns.length;)this.addColumn();for(;e.length-1){this.renameColumn("u0",i);for(;this.columns.indexOf("u1")>-1;)this.renameColumn("u1","u0")}else this.addColumn(i);for(t=0;t=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(r[n],10)+1)),r[n]=this.normalizeColumnStoreValue(this.columns[n],r[n]);if(!1===this.updateKeysOnInsert(r,t))return!1;this.data.push(r)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var r,n=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a-1&&null===t)return _throw(new jSQL_Error("0072"));null===t&&void 0!==r.default&&(t=r.default);var n=jSQL.types.getByType(r.type.toUpperCase()).serialize(t,r.args);return!isNaN(parseFloat(n))&&isFinite(n)||"string"==typeof n?n:_throw(new jSQL_Error("0020"))},jSQLTable.prototype.normalizeColumnFetchValue=function(e,t){var r=this.types[this.colmap[e]];return jSQL.types.getByType(r.type.toUpperCase()).unserialize(t,r.args)},jSQLLexer.prototype.getNextToken=function(){for(var e,t=0;t/gi,type:"SYMBOL",name:"NOT EQUAL"},{pattern:/\(/gi,type:"SYMBOL",name:"LEFT PEREN"},{pattern:/\)/gi,type:"SYMBOL",name:"RIGHT PEREN"},{pattern:/,/gi,type:"SYMBOL",name:"COMMA"},{pattern:/\?/gi,type:"SYMBOL",name:"QUESTION MARK"},{pattern:/,/gi,type:"SYMBOL",name:"COMMA"},{pattern:/\*/gi,type:"SYMBOL",name:"ASTERISK"},{pattern:/;/gi,type:"SYMBOL",name:"SEMICOLON"},{pattern:/=/gi,type:"SYMBOL",name:"EQUALS"},{pattern:/>/gi,type:"SYMBOL",name:"GREATER THAN"},{pattern:/500){for(mute_jsql_errors=!1,e.isLoading=!1,e.loaded=!0;e.loadingCallbacks.length;)e.loadingCallbacks.shift()();return}setTimeout(function(){r(n+1)},10)}}(0)},e.init=function(t){if("function"!=typeof t&&(t=function(){}),e.initiated=!0,isNode)e.api=new API.nodeAPI,e.api.init([{name:"jSQL_data_schema",rows:[]}],t);else{var r=e.api_user_priority.concat(e.api_default_priority),n=[],i=!1;!function a(s){if(s>=r.length&&!i)return _throw(new jSQL_Error("0063"));if(-1===e.api_default_priority.indexOf(r[s]))return a(1+s);if(n.indexOf(r[s])>-1)return a(1+s);try{e.api=new API[r[s]],e.api.init([{name:"jSQL_data_schema",rows:[]}],t),i=!0}catch(e){i=!1}i||a(1+s)}(0)}}};function createTable(e,t,r,n,i){var a=void 0===t&&void 0===r&&"object"==typeof e&&void 0===n,s=Array.isArray(t)&&void 0===r&&"object"==typeof e&&void 0===n;if(a||s)for(var o in s&&(n=void 0===t?[]:t),void 0===n&&(n=[]),t=[],r=[],e)if(e.hasOwnProperty(o)){var u=e[o];e=o;for(var l=0;l