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 a48fe48..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 3.3.19 - *Now available without a prescription!* +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 32adeca..aaded17 100644 --- a/jSQL.js +++ b/jSQL.js @@ -1,5 +1,5 @@ /** - * jsql-official - v3.3.19 + * jsql-official - v4.3.1 * 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,15 @@ 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 + self.tempTables = []; // 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, @@ -711,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); } @@ -848,20 +859,77 @@ 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; + return this; + }; + + 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, 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; + + 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.table.alias == table){ + tableName = this.table.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.table.alias == table){ + tableName = this.table.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'; + + return jSQLSelectQuery.processJoin(this); + }; this.where = function(column){ + jSQLSelectQuery.processColumns(this); return this.whereClause.where(column); }; this.execute = function(){ + jSQLSelectQuery.processColumns(this); var resultRowIndexes = this.whereClause.getResultRowIndexes(); var resultRows = []; @@ -871,24 +939,34 @@ function jSQLSelectQuery(){ 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 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