From 49ecb62197eb24c811b33d248677b852564af4d6 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 23 Apr 2018 00:23:02 -0400 Subject: [PATCH 1/7] joins --- package.json | 2 +- src/error_handling/jSQL_Error.js | 7 +++- src/query_types/jSQLQuery.js | 5 ++- src/query_types/jSQLSelectQuery.js | 65 +++++++++++++++++++++++++++--- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 93f6f9b..045b416 100755 --- a/package.json +++ b/package.json @@ -45,4 +45,4 @@ "istanbul": "^0.4.5", "mocha": "^4.0.1" } -} \ No newline at end of file +} diff --git a/src/error_handling/jSQL_Error.js b/src/error_handling/jSQL_Error.js index 1aefb0a..ffdeaeb 100644 --- a/src/error_handling/jSQL_Error.js +++ b/src/error_handling/jSQL_Error.js @@ -79,5 +79,10 @@ jSQL_Error.message_codes = { "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." + "0072": "Inserting null into a non-null column.", + "0073": "No column name given.", + "0074": "On method called without join.", + "0075": "Unknown join table.", + "0076": "Calling Equals without join or where clause.", + "0077": "No matching table to join to." }; \ No newline at end of file diff --git a/src/query_types/jSQLQuery.js b/src/query_types/jSQLQuery.js index 4887a90..1215a70 100644 --- a/src/query_types/jSQLQuery.js +++ b/src/query_types/jSQLQuery.js @@ -12,11 +12,14 @@ function jSQLQuery(type){ self.whereClause = new jSQLWhereClause(self); self.resultSet = []; self.isTemp = false; + self.selectTable = null; + self.pendingJoin = null; // table to be joined on "on" method // Methods that every query class should implement var methods = ['init', 'ifNotExists', 'execute', 'fetch', 'ignore', 'fetchAll', 'values', 'set', 'where', 'from', 'orderBy', 'asc', - 'desc', 'limit', 'distinct', 'temporary']; + 'desc', 'limit', 'distinct', 'temporary', 'join', 'innerJoin', + 'on', 'equals']; var queryTypeConstructors = { CREATE: jSQLCreateQuery, UPDATE: jSQLUpdateQuery, diff --git a/src/query_types/jSQLSelectQuery.js b/src/query_types/jSQLSelectQuery.js index 724c09d..956c60e 100644 --- a/src/query_types/jSQLSelectQuery.js +++ b/src/query_types/jSQLSelectQuery.js @@ -1,16 +1,69 @@ function jSQLSelectQuery(){ this.init = function(columns){ - this.columns = Array.isArray(columns) ? columns : [columns]; + var columns = Array.isArray(columns) ? columns : [columns]; + for(var i=columns.length; i--;){ + if("string" == typeof columns[i]) columns[i] = {name: columns[i], alias:columns[i]}; + if(string !== typeof columns[i].name) return _throw(new jSQL_Error("0073")); + if(!columns[i].alias) columns[i].alias = columns[i].name; + } + this.columns = columns; + return this; + }; + this.from = function(table, alias){ + if(undefined === jSQL.tables[table]) return _throw(new jSQL_Error("0021")); + this.selectTable = {name:table, alias:alias}; + + // this.table = jSQL.tables[table]; + // account for this in the execute function + // if(this.columns[0] == "*") this.columns = this.table.columns; return this; }; - this.from = function(table){ - if(undefined === jSQL.tables[table]) - return _throw(new jSQL_Error("0021")); - this.table = jSQL.tables[table]; - if(this.columns[0] == "*") this.columns = this.table.columns; + this.join=function(table, alias){return this.innerJoin(table, alias);}; + this.innerJoin = function(table, alias){ + if(!alias) alias = table; + if(undefined === jSQL.tables[table]) return _throw(new jSQL_Error("0021")); + this.pendingJoin = {table: table, alias: alias, type: 'inner', onTable:null, onColumn:null, matchType: false, matchTable: null, matchColumn: null}; return this; }; + this.on = function(table, column){ + var tableName; + // make sure the given table is either pending join or already in the tables list + if(!this.pendingJoin) return _throw(new jSQL_Error("0074")); + var joinTableExists = false; + if(this.selectTable.alias == table){ + tableName = this.selectTable.name; + joinTableExists = true; + } + if(!joinTableExists && this.pendingJoin.alias == table){ + tableName = this.pendingJoin.table; + joinTableExists = true; + } + if(!joinTableExists) return _throw(new jSQL_Error("0075")); + if(!~jSQL.tables[tableName].columns.indexOf(column)) return _throw(new jSQL_Error("0013")); + this.pendingJoin.onTable = table; + this.pendingJoin.onColumn = column; + return this; + }; + this.equals = function(table, column){ + if(!this.pendingJoin) return _throw(new jSQL_Error("0076")); + if(!this.pendingJoin.onTable) return _throw(new jSQL_Error("0077")); + var joinTableExists = false; + var tableName = false; + if(this.selectTable.alias == table){ + tableName = this.selectTable.name; + joinTableExists = true; + } + if(!joinTableExists && this.pendingJoin.alias == table){ + tableName = this.pendingJoin.table; + joinTableExists = true; + } + if(!joinTableExists) return _throw(new jSQL_Error("0075")); + if(!~jSQL.tables[tableName].columns.indexOf(column)) return _throw(new jSQL_Error("0013")); + this.pendingJoin.matchTable = 'table'; + this.pendingJoin.matchcolumn = 'column'; + this.pendingJoin.matchType = 'equals'; + }; this.where = function(column){ return this.whereClause.where(column); }; From 66731f7db730d5473eeabe0ab69e18b44b3fd581 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 25 Apr 2018 11:22:28 -0400 Subject: [PATCH 2/7] table and column aliases --- README.md | 2 +- jSQL.js | 107 +++++++++++++++++++++++++---- jSQL.min.js | 4 +- package.json | 4 +- src/parser/jSQLWhereClause.js | 3 +- src/query_types/jSQLSelectQuery.js | 43 ++++++++---- src/table/jSQLTable.js | 2 + test/test7.js | 23 +++++++ 8 files changed, 158 insertions(+), 30 deletions(-) create mode 100644 test/test7.js diff --git a/README.md b/README.md index a48fe48..5ae0333 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.3.19 - *Now available without a prescription!* +jSQL (Official) - Version 4.0.34 - *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 32adeca..f64b97b 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v3.3.19 + * jsql-official - v4.0.34 * A persistent SQL database. * @author Rob Parham * @website http://pamblam.github.io/jSQL/ @@ -91,7 +91,12 @@ jSQL_Error.message_codes = { "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." + "0072": "Inserting null into a non-null column.", + "0073": "No column name given.", + "0074": "On method called without join.", + "0075": "Unknown join table.", + "0076": "Calling Equals without join or where clause.", + "0077": "No matching table to join to." }; function jSQL_Lexer_Error(pos, context) { @@ -385,6 +390,7 @@ function jSQLTable(name, columns, data, types, keys, auto_increment){ var self = this; self.isTemp = false; // Is a temporary table? self.name = ""; // Table name + self.alias = ""; self.columns = []; // Array of column names self.data = []; // Array of arrays self.colmap = {}; // Colmap @@ -399,6 +405,7 @@ function jSQLTable(name, columns, data, types, keys, auto_increment){ }; self.name = name; + self.alias = name; // If the types array does not exist, create it if(undefined === types) types = []; @@ -694,11 +701,14 @@ function jSQLQuery(type){ self.whereClause = new jSQLWhereClause(self); self.resultSet = []; self.isTemp = false; + self.selectTable = null; + self.pendingJoin = null; // table to be joined on "on" method // Methods that every query class should implement var methods = ['init', 'ifNotExists', 'execute', 'fetch', 'ignore', 'fetchAll', 'values', 'set', 'where', 'from', 'orderBy', 'asc', - 'desc', 'limit', 'distinct', 'temporary']; + 'desc', 'limit', 'distinct', 'temporary', 'join', 'innerJoin', + 'on', 'equals']; var queryTypeConstructors = { CREATE: jSQLCreateQuery, UPDATE: jSQLUpdateQuery, @@ -848,20 +858,85 @@ function jSQLInsertQuery(){ function jSQLSelectQuery(){ this.init = function(columns){ - this.columns = Array.isArray(columns) ? columns : [columns]; + var columns = Array.isArray(columns) ? columns : [columns]; + for(var i=columns.length; i--;){ + if("string" == typeof columns[i]) columns[i] = {table:null, name:columns[i], alias:columns[i]}; + if('string' !== typeof columns[i].name) return _throw(new jSQL_Error("0073")); + if(!columns[i].alias) columns[i].alias = columns[i].name; + if(!columns[i].table) columns[i].table = null; + } + this.columns = columns; return this; }; - this.from = function(table){ - if(undefined === jSQL.tables[table]) - return _throw(new jSQL_Error("0021")); + this.from = function(table, alias){ + if(undefined === jSQL.tables[table]) return _throw(new jSQL_Error("0021")); this.table = jSQL.tables[table]; - if(this.columns[0] == "*") this.columns = this.table.columns; + if(alias) this.table.alias = alias; + + // check for * in column names + for(var i=0; ie+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)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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&&-1=this.table.auto_inc_seq&&(this.table.auto_inc_seq=this.newvals[this.columns[o]]+1)),a[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===a[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));l.push(a[f])}if(l=JSON.stringify(l),this.table.keys.primary.map.hasOwnProperty(l)&&this.table.keys.primary.map[l]!==s)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===a[L])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));d.push(a[L])}if(d=JSON.stringify(d),p.map.hasOwnProperty(d)&&p.map[d]!==s)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(d)}i.push({rowIndex:s,row:a,pk_vals:l,uni_vals:y})}for(t=0;t",value:e}),S.pendingColumn="",S)},S.contains=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0049")):(S.conditions.push({col:S.pendingColumn,type:"%%",value:e}),S.pendingColumn="",S)},S.endsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0050")):(S.conditions.push({col:S.pendingColumn,type:"%-",value:e}),S.pendingColumn="",S)},S.beginsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0051")):(S.conditions.push({col:S.pendingColumn,type:"-%",value:e}),S.pendingColumn="",S)},S.and=function(e){return S.where(e)},S.or=function(e){return S.finalConditions.push(S.conditions),S.conditions=[],S.where(e)},S.limit=function(e,t){return S.LIMIT=parseInt(e),void 0!==t&&(S.OFFSET=parseInt(t)),S},S.orderBy=function(e){return Array.isArray(e)||(e=[e]),S.sortColumn=e,S},S.asc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0052")):(S.sortDirection="ASC",S)},S.desc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0053")):(S.sortDirection="DESC",S)},S.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(l))||l<=o.value)&&(s=!1);break;case"<":(isNaN(parseFloat(l))||l>=o.value)&&(s=!1);break;case"=":l!=o.value&&(s=!1);break;case"!=":break;case"%%":l.indexOf(o.value)<0&&(s=!1);break;case"%-":l.indexOf(o.value)!=l.length-o.value.length&&(s=!1);break;case"-%":0!=l.indexOf(o.value)&&(s=!1)}if(!s)break}if(s){r=!0;break}}r&&e.push(t)}if(0s[n]?1:e(t+1)}(0)}),"DESC"==S.sortDirection&&e.reverse()),S.isDistinct){var h=[];for(t=0;tS.LIMIT&&(S.OFFSET>e.length&&(e=[]),S.LIMIT>e.length&&(S.LIMIT=e.length),e.length&&(e=e.slice(S.OFFSET,S.OFFSET+S.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var r;for(this.columns=e,r=0;rthis.columns.length;)this.addColumn();for(;e.length=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=[],s=0;s/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:/=n.length&&!s)return _throw(new jSQL_Error("0063"));if(-1===u.api_default_priority.indexOf(n[t]))return e(1+t);if(-1e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var f=this.table.colmap[h];if(null===s[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[f])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==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:u,uni_vals:y})}for(t=0;t",value:e}),d.pendingColumn="",d)},d.contains=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0049")):(d.conditions.push({col:d.pendingColumn,type:"%%",value:e}),d.pendingColumn="",d)},d.endsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0050")):(d.conditions.push({col:d.pendingColumn,type:"%-",value:e}),d.pendingColumn="",d)},d.beginsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0051")):(d.conditions.push({col:d.pendingColumn,type:"-%",value:e}),d.pendingColumn="",d)},d.and=function(e){return d.where(e)},d.or=function(e){return d.finalConditions.push(d.conditions),d.conditions=[],d.where(e)},d.limit=function(e,t){return d.LIMIT=parseInt(e),void 0!==t&&(d.OFFSET=parseInt(t)),d},d.orderBy=function(e){return Array.isArray(e)||(e=[e]),d.sortColumn=e,d},d.asc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0052")):(d.sortDirection="ASC",d)},d.desc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0053")):(d.sortDirection="DESC",d)},d.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==d.sortDirection&&e.reverse()),d.isDistinct){var h=[];for(t=0;td.LIMIT&&(d.OFFSET>e.length&&(e=[]),d.LIMIT>e.length&&(d.LIMIT=e.length),e.length&&(e=e.slice(d.OFFSET,d.OFFSET+d.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1 Date: Wed, 25 Apr 2018 11:24:38 -0400 Subject: [PATCH 3/7] update minor version number --- .codeclimate.yml | 20 -------------------- README.md | 2 +- jSQL.js | 4 ++-- jSQL.min.js | 4 ++-- package.json | 2 +- 5 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 23e4089..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,20 +0,0 @@ - -engines: - eslint: - enabled: true - fixme: - enabled: true - rubocop: - enabled: true -ratings: - paths: - - "**.js" -exclude_paths: -- "plugins/" -- "jSQL.js" -- "tests/" -- "Gruntfile.js" -- "LICENSE" -- "README.md" -- "jSQL.min.js" -- "package.json" diff --git a/README.md b/README.md index 5ae0333..a47d460 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 4.0.34 - *Now available without a prescription!* +jSQL (Official) - Version 4.1.1 - *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 f64b97b..fc45198 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v4.0.34 + * jsql-official - v4.1.1 * A persistent SQL database. * @author Rob Parham * @website http://pamblam.github.io/jSQL/ @@ -2920,7 +2920,7 @@ function jsql_import(dump){ } return { - version: "4.0.34", + version: "4.1.1", tables: {}, query: jSQLParseQuery, createTable: createTable, diff --git a/jSQL.min.js b/jSQL.min.js index 2b0c2dd..1e03987 100644 --- a/jSQL.min.js +++ b/jSQL.min.js @@ -1,2 +1,2 @@ -/*! jsql-official - v4.0.34 */ -!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),this.message=jSQL_Error.message_codes[e],this.toString=function(){return"jSQL Error #"+this.error+" - "+this.message}}function jSQL_Lexer_Error(e,t){var n=t.length>e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var f=this.table.colmap[h];if(null===s[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[f])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==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:u,uni_vals:y})}for(t=0;t",value:e}),d.pendingColumn="",d)},d.contains=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0049")):(d.conditions.push({col:d.pendingColumn,type:"%%",value:e}),d.pendingColumn="",d)},d.endsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0050")):(d.conditions.push({col:d.pendingColumn,type:"%-",value:e}),d.pendingColumn="",d)},d.beginsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0051")):(d.conditions.push({col:d.pendingColumn,type:"-%",value:e}),d.pendingColumn="",d)},d.and=function(e){return d.where(e)},d.or=function(e){return d.finalConditions.push(d.conditions),d.conditions=[],d.where(e)},d.limit=function(e,t){return d.LIMIT=parseInt(e),void 0!==t&&(d.OFFSET=parseInt(t)),d},d.orderBy=function(e){return Array.isArray(e)||(e=[e]),d.sortColumn=e,d},d.asc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0052")):(d.sortDirection="ASC",d)},d.desc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0053")):(d.sortDirection="DESC",d)},d.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==d.sortDirection&&e.reverse()),d.isDistinct){var h=[];for(t=0;td.LIMIT&&(d.OFFSET>e.length&&(e=[]),d.LIMIT>e.length&&(d.LIMIT=e.length),e.length&&(e=e.slice(d.OFFSET,d.OFFSET+d.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var f=this.table.colmap[h];if(null===s[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[f])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==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:u,uni_vals:y})}for(t=0;t",value:e}),d.pendingColumn="",d)},d.contains=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0049")):(d.conditions.push({col:d.pendingColumn,type:"%%",value:e}),d.pendingColumn="",d)},d.endsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0050")):(d.conditions.push({col:d.pendingColumn,type:"%-",value:e}),d.pendingColumn="",d)},d.beginsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0051")):(d.conditions.push({col:d.pendingColumn,type:"-%",value:e}),d.pendingColumn="",d)},d.and=function(e){return d.where(e)},d.or=function(e){return d.finalConditions.push(d.conditions),d.conditions=[],d.where(e)},d.limit=function(e,t){return d.LIMIT=parseInt(e),void 0!==t&&(d.OFFSET=parseInt(t)),d},d.orderBy=function(e){return Array.isArray(e)||(e=[e]),d.sortColumn=e,d},d.asc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0052")):(d.sortDirection="ASC",d)},d.desc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0053")):(d.sortDirection="DESC",d)},d.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==d.sortDirection&&e.reverse()),d.isDistinct){var h=[];for(t=0;td.LIMIT&&(d.OFFSET>e.length&&(e=[]),d.LIMIT>e.length&&(d.LIMIT=e.length),e.length&&(e=e.slice(d.OFFSET,d.OFFSET+d.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1 Date: Wed, 25 Apr 2018 22:42:22 -0400 Subject: [PATCH 4/7] inner join is working! --- README.md | 2 +- jSQL.js | 162 +++++++++++++++++++++++++---- jSQL.min.js | 4 +- package.json | 2 +- src/query_types/jSQLQuery.js | 3 +- src/query_types/jSQLSelectQuery.js | 156 ++++++++++++++++++++++++--- test/jointest.js | 14 +++ 7 files changed, 301 insertions(+), 42 deletions(-) create mode 100644 test/jointest.js diff --git a/README.md b/README.md index a47d460..817ec95 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 4.1.1 - *Now available without a prescription!* +jSQL (Official) - Version 4.1.31 - *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 fc45198..774c60b 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v4.1.1 + * jsql-official - v4.1.31 * A persistent SQL database. * @author Rob Parham * @website http://pamblam.github.io/jSQL/ @@ -703,6 +703,7 @@ function jSQLQuery(type){ self.isTemp = false; self.selectTable = null; self.pendingJoin = null; // table to be joined on "on" method + self.tempTables = []; // Methods that every query class should implement var methods = ['init', 'ifNotExists', 'execute', 'fetch', 'ignore', @@ -721,7 +722,7 @@ function jSQLQuery(type){ self[methods[i]] = function(){ var q = new queryTypeConstructors[self.type]; if(typeof q[methods[i]] == "function") return q[methods[i]].apply(self, arguments); - else return _throw(new jSQL_Error("0022")); + return _throw(new jSQL_Error("0022")); }; })(i); } @@ -872,28 +873,17 @@ function jSQLSelectQuery(){ if(undefined === jSQL.tables[table]) return _throw(new jSQL_Error("0021")); this.table = jSQL.tables[table]; if(alias) this.table.alias = alias; - - // check for * in column names - for(var i=0; ie+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var f=this.table.colmap[h];if(null===s[f])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[f])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==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:u,uni_vals:y})}for(t=0;t",value:e}),d.pendingColumn="",d)},d.contains=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0049")):(d.conditions.push({col:d.pendingColumn,type:"%%",value:e}),d.pendingColumn="",d)},d.endsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0050")):(d.conditions.push({col:d.pendingColumn,type:"%-",value:e}),d.pendingColumn="",d)},d.beginsWith=function(e){return""==d.pendingColumn?_throw(new jSQL_Error("0051")):(d.conditions.push({col:d.pendingColumn,type:"-%",value:e}),d.pendingColumn="",d)},d.and=function(e){return d.where(e)},d.or=function(e){return d.finalConditions.push(d.conditions),d.conditions=[],d.where(e)},d.limit=function(e,t){return d.LIMIT=parseInt(e),void 0!==t&&(d.OFFSET=parseInt(t)),d},d.orderBy=function(e){return Array.isArray(e)||(e=[e]),d.sortColumn=e,d},d.asc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0052")):(d.sortDirection="ASC",d)},d.desc=function(){return""==d.sortColumn?_throw(new jSQL_Error("0053")):(d.sortDirection="DESC",d)},d.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==d.sortDirection&&e.reverse()),d.isDistinct){var h=[];for(t=0;td.LIMIT&&(d.OFFSET>e.length&&(e=[]),d.LIMIT>e.length&&(d.LIMIT=e.length),e.length&&(e=e.slice(d.OFFSET,d.OFFSET+d.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var p=this.table.colmap[h];if(null===s[p])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[p])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var f,y=[],m=0;f=this.table.keys.unique[m];m++){for(var d=Array.isArray(f.column)?f.column:[f.column],S=[],L=0;E=d[L];L++){var g=this.table.colmap[E];if(null===s[g])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));S.push(s[g])}if(S=JSON.stringify(S),f.map.hasOwnProperty(S)&&f.map[S]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(S)}i.push({rowIndex:a,row:s,pk_vals:u,uni_vals:y})}for(t=0;t",value:e}),S.pendingColumn="",S)},S.contains=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0049")):(S.conditions.push({col:S.pendingColumn,type:"%%",value:e}),S.pendingColumn="",S)},S.endsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0050")):(S.conditions.push({col:S.pendingColumn,type:"%-",value:e}),S.pendingColumn="",S)},S.beginsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0051")):(S.conditions.push({col:S.pendingColumn,type:"-%",value:e}),S.pendingColumn="",S)},S.and=function(e){return S.where(e)},S.or=function(e){return S.finalConditions.push(S.conditions),S.conditions=[],S.where(e)},S.limit=function(e,t){return S.LIMIT=parseInt(e),void 0!==t&&(S.OFFSET=parseInt(t)),S},S.orderBy=function(e){return Array.isArray(e)||(e=[e]),S.sortColumn=e,S},S.asc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0052")):(S.sortDirection="ASC",S)},S.desc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0053")):(S.sortDirection="DESC",S)},S.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==S.sortDirection&&e.reverse()),S.isDistinct){var h=[];for(t=0;tS.LIMIT&&(S.OFFSET>e.length&&(e=[]),S.LIMIT>e.length&&(S.LIMIT=e.length),e.length&&(e=e.slice(S.OFFSET,S.OFFSET+S.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1 Date: Wed, 25 Apr 2018 22:43:32 -0400 Subject: [PATCH 5/7] inner join is working! --- README.md | 2 +- jSQL.js | 4 ++-- jSQL.min.js | 4 ++-- package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 817ec95..922890d 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 4.1.31 - *Now available without a prescription!* +jSQL (Official) - Version 4.2.1 - *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 774c60b..40bdcff 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v4.1.31 + * jsql-official - v4.2.1 * A persistent SQL database. * @author Rob Parham * @website http://pamblam.github.io/jSQL/ @@ -3042,7 +3042,7 @@ function jsql_import(dump){ } return { - version: "4.1.31", + version: "4.2.1", tables: {}, query: jSQLParseQuery, createTable: createTable, diff --git a/jSQL.min.js b/jSQL.min.js index 984fb86..58c29c4 100644 --- a/jSQL.min.js +++ b/jSQL.min.js @@ -1,2 +1,2 @@ -/*! jsql-official - v4.1.31 */ -!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),this.message=jSQL_Error.message_codes[e],this.toString=function(){return"jSQL Error #"+this.error+" - "+this.message}}function jSQL_Lexer_Error(e,t){var n=t.length>e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var p=this.table.colmap[h];if(null===s[p])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[p])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var f,y=[],m=0;f=this.table.keys.unique[m];m++){for(var d=Array.isArray(f.column)?f.column:[f.column],S=[],L=0;E=d[L];L++){var g=this.table.colmap[E];if(null===s[g])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));S.push(s[g])}if(S=JSON.stringify(S),f.map.hasOwnProperty(S)&&f.map[S]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(S)}i.push({rowIndex:a,row:s,pk_vals:u,uni_vals:y})}for(t=0;t",value:e}),S.pendingColumn="",S)},S.contains=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0049")):(S.conditions.push({col:S.pendingColumn,type:"%%",value:e}),S.pendingColumn="",S)},S.endsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0050")):(S.conditions.push({col:S.pendingColumn,type:"%-",value:e}),S.pendingColumn="",S)},S.beginsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0051")):(S.conditions.push({col:S.pendingColumn,type:"-%",value:e}),S.pendingColumn="",S)},S.and=function(e){return S.where(e)},S.or=function(e){return S.finalConditions.push(S.conditions),S.conditions=[],S.where(e)},S.limit=function(e,t){return S.LIMIT=parseInt(e),void 0!==t&&(S.OFFSET=parseInt(t)),S},S.orderBy=function(e){return Array.isArray(e)||(e=[e]),S.sortColumn=e,S},S.asc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0052")):(S.sortDirection="ASC",S)},S.desc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0053")):(S.sortDirection="DESC",S)},S.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==S.sortDirection&&e.reverse()),S.isDistinct){var h=[];for(t=0;tS.LIMIT&&(S.OFFSET>e.length&&(e=[]),S.LIMIT>e.length&&(S.LIMIT=e.length),e.length&&(e=e.slice(S.OFFSET,S.OFFSET+S.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var p=this.table.colmap[h];if(null===s[p])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[p])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var f,y=[],m=0;f=this.table.keys.unique[m];m++){for(var d=Array.isArray(f.column)?f.column:[f.column],S=[],L=0;E=d[L];L++){var g=this.table.colmap[E];if(null===s[g])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));S.push(s[g])}if(S=JSON.stringify(S),f.map.hasOwnProperty(S)&&f.map[S]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(S)}i.push({rowIndex:a,row:s,pk_vals:u,uni_vals:y})}for(t=0;t",value:e}),S.pendingColumn="",S)},S.contains=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0049")):(S.conditions.push({col:S.pendingColumn,type:"%%",value:e}),S.pendingColumn="",S)},S.endsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0050")):(S.conditions.push({col:S.pendingColumn,type:"%-",value:e}),S.pendingColumn="",S)},S.beginsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0051")):(S.conditions.push({col:S.pendingColumn,type:"-%",value:e}),S.pendingColumn="",S)},S.and=function(e){return S.where(e)},S.or=function(e){return S.finalConditions.push(S.conditions),S.conditions=[],S.where(e)},S.limit=function(e,t){return S.LIMIT=parseInt(e),void 0!==t&&(S.OFFSET=parseInt(t)),S},S.orderBy=function(e){return Array.isArray(e)||(e=[e]),S.sortColumn=e,S},S.asc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0052")):(S.sortDirection="ASC",S)},S.desc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0053")):(S.sortDirection="DESC",S)},S.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==S.sortDirection&&e.reverse()),S.isDistinct){var h=[];for(t=0;tS.LIMIT&&(S.OFFSET>e.length&&(e=[]),S.LIMIT>e.length&&(S.LIMIT=e.length),e.length&&(e=e.slice(S.OFFSET,S.OFFSET+S.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1 Date: Wed, 25 Apr 2018 23:12:16 -0400 Subject: [PATCH 6/7] new tagline --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 922890d..89d3dc0 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 4.2.1 - *Now available without a prescription!* +jSQL (Official) - Version 4.2.1 - *Made from meat by-products!* [![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) From f488b74e133519f469acf170409ff6f7040100dd Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 26 Apr 2018 16:12:17 -0400 Subject: [PATCH 7/7] aliases and joins tested and improved --- README.md | 2 +- jSQL.js | 45 +++++++++++++----------------- jSQL.min.js | 4 +-- package.json | 2 +- src/query_types/jSQLSelectQuery.js | 41 +++++++++++---------------- test/jointest.js | 13 +++++++-- 6 files changed, 50 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 89d3dc0..0c897f6 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 4.2.1 - *Made from meat by-products!* +jSQL (Official) - Version 4.3.1 - *Made from meat by-products!* [![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 40bdcff..aaded17 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v4.2.1 + * jsql-official - v4.3.1 * A persistent SQL database. * @author Rob Parham * @website http://pamblam.github.io/jSQL/ @@ -879,7 +879,7 @@ function jSQLSelectQuery(){ this.innerJoin = function(table, alias){ if(!alias) alias = table; if(undefined === jSQL.tables[table]) return _throw(new jSQL_Error("0021")); - this.pendingJoin = {table: table, alias: alias, type: 'inner', onTable:null, onColumn:null, matchType: false, matchTable: null, matchColumn: null}; + this.pendingJoin = {table: table, alias: alias, fromTable:this.table.name, fromAlias:this.table.alias, type: 'inner', onTable:null, onColumn:null, matchType: false, matchTable: null, matchColumn: null}; return this; }; this.join=this.innerJoin; @@ -944,17 +944,14 @@ function jSQLSelectQuery(){ results.push(row); } this.resultSet = results; - -// for(var i=0; ie+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var p=this.table.colmap[h];if(null===s[p])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[p])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var f,y=[],m=0;f=this.table.keys.unique[m];m++){for(var d=Array.isArray(f.column)?f.column:[f.column],S=[],L=0;E=d[L];L++){var g=this.table.colmap[E];if(null===s[g])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));S.push(s[g])}if(S=JSON.stringify(S),f.map.hasOwnProperty(S)&&f.map[S]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(S)}i.push({rowIndex:a,row:s,pk_vals:u,uni_vals:y})}for(t=0;t",value:e}),S.pendingColumn="",S)},S.contains=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0049")):(S.conditions.push({col:S.pendingColumn,type:"%%",value:e}),S.pendingColumn="",S)},S.endsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0050")):(S.conditions.push({col:S.pendingColumn,type:"%-",value:e}),S.pendingColumn="",S)},S.beginsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0051")):(S.conditions.push({col:S.pendingColumn,type:"-%",value:e}),S.pendingColumn="",S)},S.and=function(e){return S.where(e)},S.or=function(e){return S.finalConditions.push(S.conditions),S.conditions=[],S.where(e)},S.limit=function(e,t){return S.LIMIT=parseInt(e),void 0!==t&&(S.OFFSET=parseInt(t)),S},S.orderBy=function(e){return Array.isArray(e)||(e=[e]),S.sortColumn=e,S},S.asc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0052")):(S.sortDirection="ASC",S)},S.desc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0053")):(S.sortDirection="DESC",S)},S.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==S.sortDirection&&e.reverse()),S.isDistinct){var h=[];for(t=0;tS.LIMIT&&(S.OFFSET>e.length&&(e=[]),S.LIMIT>e.length&&(S.LIMIT=e.length),e.length&&(e=e.slice(S.OFFSET,S.OFFSET+S.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1e+25?25:t.length-e,r=t.substr(e,n);this.error="0070",this.message="Unknown token near char "+e+" of "+t.length+' "'+r+'".',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 n=new Error;n.stack&&(this.stack=n.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.","0073":"No column name given.","0074":"On method called without join.","0075":"Unknown join table.","0076":"Calling Equals without join or where clause.","0077":"No matching table to join to."};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 n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))},unserialize:function(e,t){if("jsqlNull"===e)return null;for(var n=t.length;n--;)if(e===removeQuotes(t[n]))return e;return _throw(new jSQL_Error("0068"))}},{type:"TINYINT",serialize:function(e,t){return null===e&&(e=0),!isNaN(parseInt(e))&&isFinite(e)&&-128<=e&&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)&&-32768<=e&&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)&&-8388608<=e&&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)&&-2147483648<=e&&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)&&-9007199254740991<=e&&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 n=t[0]>>0,r=" ";return e.length>n?e.substr(0,t[0]):((n-=e.length)>r.length&&(r+=r.repeat(n/r.length)),String(e)+r.slice(0,n))}},{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&&-1=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 l=this.table.keys.primary.column,u=!1;if(!1!==l){var h;Array.isArray(l)||(l=[l]),u=[];for(var c=0;h=l[c];c++){var p=this.table.colmap[h];if(null===s[p])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0016"));u.push(s[p])}if(u=JSON.stringify(u),this.table.keys.primary.map.hasOwnProperty(u)&&this.table.keys.primary.map[u]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0017"))}for(var f,y=[],m=0;f=this.table.keys.unique[m];m++){for(var d=Array.isArray(f.column)?f.column:[f.column],S=[],L=0;E=d[L];L++){var g=this.table.colmap[E];if(null===s[g])return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0018"));S.push(s[g])}if(S=JSON.stringify(S),f.map.hasOwnProperty(S)&&f.map[S]!==a)return!0===this.ignoreFlag?this:_throw(new jSQL_Error("0019"));y.push(S)}i.push({rowIndex:a,row:s,pk_vals:u,uni_vals:y})}for(t=0;t",value:e}),S.pendingColumn="",S)},S.contains=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0049")):(S.conditions.push({col:S.pendingColumn,type:"%%",value:e}),S.pendingColumn="",S)},S.endsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0050")):(S.conditions.push({col:S.pendingColumn,type:"%-",value:e}),S.pendingColumn="",S)},S.beginsWith=function(e){return""==S.pendingColumn?_throw(new jSQL_Error("0051")):(S.conditions.push({col:S.pendingColumn,type:"-%",value:e}),S.pendingColumn="",S)},S.and=function(e){return S.where(e)},S.or=function(e){return S.finalConditions.push(S.conditions),S.conditions=[],S.where(e)},S.limit=function(e,t){return S.LIMIT=parseInt(e),void 0!==t&&(S.OFFSET=parseInt(t)),S},S.orderBy=function(e){return Array.isArray(e)||(e=[e]),S.sortColumn=e,S},S.asc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0052")):(S.sortDirection="ASC",S)},S.desc=function(){return""==S.sortColumn?_throw(new jSQL_Error("0053")):(S.sortDirection="DESC",S)},S.execute=function(e){if(void 0===e&&(e=[]),0":(isNaN(parseFloat(u))||u<=o.value)&&(a=!1);break;case"<":(isNaN(parseFloat(u))||u>=o.value)&&(a=!1);break;case"=":u!=o.value&&(a=!1);break;case"!=":break;case"%%":u.indexOf(o.value)<0&&(a=!1);break;case"%-":u.indexOf(o.value)!=u.length-o.value.length&&(a=!1);break;case"-%":0!=u.indexOf(o.value)&&(a=!1)}if(!a)break}if(a){n=!0;break}}n&&e.push(t)}if(0a[r]?1:e(t+1)}(0)}),"DESC"==S.sortDirection&&e.reverse()),S.isDistinct){var h=[];for(t=0;tS.LIMIT&&(S.OFFSET>e.length&&(e=[]),S.LIMIT>e.length&&(S.LIMIT=e.length),e.length&&(e=e.slice(S.OFFSET,S.OFFSET+S.LIMIT))),e}}jSQLTable.prototype.initColumns=function(e,t){var n;for(this.columns=e,n=0;nthis.columns.length;)this.addColumn();for(;e.length=this.auto_inc_seq&&(this.auto_inc_seq=parseInt(n[r],10)+1)),n[r]=this.normalizeColumnStoreValue(this.columns[r],n[r]);if(!1===this.updateKeysOnInsert(n,t))return!1;this.data.push(n)},jSQLTable.prototype.updateKeysOnInsert=function(e,t){if(this.keys.primary.column){for(var n,r=Array.isArray(this.keys.primary.column)?this.keys.primary.column:[this.keys.primary.column],i=[],a=0;a/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:/=r.length&&!a)return _throw(new jSQL_Error("0063"));if(-1===l.api_default_priority.indexOf(r[t]))return e(1+t);if(-1 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy