File: src/js/Dialect.min.js

Recommend this page to a friend!
  Classes of Nikos M.  >  Dialect PHP SQL Query Builder  >  src/js/Dialect.min.js  >  Download  
File: src/js/Dialect.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Dialect PHP SQL Query Builder
Build SQL queries from templates
Author: By
Last change: v.1.3.0

* support for UNION [ALL] clause
* getting sql string DOES NOT reset the instance, can call .sql() multiple times
* update examples and tests
Date: 4 months ago
Size: 47,639 bytes
 

Contents

Class file image Download
/**
*   Dialect,
*   a simple and flexible Cross-Platform & Cross-Vendor SQL Query Builder for PHP, Python, JavaScript
*
*   @version: 1.3.0
*   https://github.com/foo123/Dialect
*
*   Abstract the construction of SQL queries
*   Support multiple DB vendors
*   Intuitive and Flexible API
**/
!function(n,l,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(n.$deps=n.$deps||{})&&(n.EXPORTED_SYMBOLS=[l])&&(n[l]=n.$deps[l]=t.call(n)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[l]=t.call(n)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System.import?System.register(l,[],function(e){e(l,t.call(n))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(l)?define(l,["module"],function(e){return t.moduleUri=e.uri,t.call(n)}):l in n||(n[l]=t.call(n)||1)&&"function"==typeof define&&define.amd&&define(function(){return n[l]})}("undefined"!=typeof self?self:this,"Dialect",function(c){"use strict";var n="prototype",l=Object.keys,t=Object[n].toString,g=Object[n].hasOwnProperty,X="charAt",u="charCodeAt",s=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,i=/^\s+|\s+$/g,K=String[n].trim?function(e){return e.trim()}:function(e){return e.replace(i,"")},o=String.fromCharCode(0);function J(){return J.GUID+=1,e((new Date).getTime().toString(16),12)+"--"+e(J.GUID.toString(16),4)}function a(e,n,l){var t=this;if(!(t instanceof a))return new a(e,n,l);t.id=null,t.tpl=null,t._renderer=null,t._args=[e||"",n||a.defaultArgs,l],t._parsed=!1}function Q(e,n){return!(!e||!g.call(e,n))}function e(e,n,l,t){var s=String(e);if(l=l||"0",t)for(;s.length<n;)s+=l;else for(;s.length<n;)s=l+s;return s}function $(e,n,l){for(var t,s="";n<l&&(" "===(t=e[X](n))||"\r"===t||"\t"===t||"\v"===t||"\0"===t);)s+=t,n+=1;return s}function d(e,n){var l,t,s,i=e.length;if(i&&n.length)for(l="",s=0;s<i;s++)l+=t=e[X](s),"\n"===t&&(l+=n);else l=e;return l}function T(e,n,l,t){var s,i,r,u,o=0;if(n)for(s=e,i=n.length,r=0,o=1;r<i;){if(u=n[r++],null==s||null==s[u]){o=0;break}s=s[u]}if(!o&&l)for(s=e,i=l.length,r=0,o=1;r<i;){if(u=l[r++],null==s||null==s[u]){o=0;break}s=s[u]}if(!o&&null!=t&&t!==e){if(n)for(s=t,i=n.length,r=0,o=1;r<i;){if(u=n[r++],null==s||null==s[u]){o=0;break}s=s[u]}if(!o&&l)for(s=t,i=l.length,r=0,o=1;r<i;){if(u=l[r++],null==s||null==s[u]){o=0;break}s=s[u]}}return o?s:null}function Z(e,n){this.prev=e||null,this.value=n||null}function z(e,n){n&&(n.next=this),this.node=e||null,this.prev=n||null,this.next=null}function p(e,n,l,t,s,i,r){var u,o,a,c,f,d,p,_,h=null,E="";if(-1===n.type){if((u=n.opt_args)&&u.value[5])for(;u;){if(a=T(e,(o=u.value)[1],[String(o[0])],o[6]?null:r),null===h&&n.name===o[0]&&(h=a),0===o[2]&&null==a||1===o[2]&&null!=a)return"";u=u.prev}}else h=T(e,n.key,[String(n.name)],n.loc?null:r);if(_=(c=m(h))?h.length:-1,c&&_>n.start)for(f=n.start,d=-1===n.end?_-1:Math.min(n.end,_-1),p=f;p<=d;p++)E+=v(e,n.tpl,l,t,p,i,r);else c||n.start!==n.end||(E=v(e,n.tpl,l,t,null,i,r));return E}function f(e,n,l,t,s,i,r){var u,o,a,c,f="";if(n.stpl&&(Q(l,n.stpl)||Q(_.subGlobal,n.stpl)||Q(t,n.stpl)||Q(t,"*")||Q(_.fnGlobal,n.stpl)||Q(_.fnGlobal,"*")))if(u=T(e,n.key,[String(n.name)],n.loc?null:r),Q(l,n.stpl)||Q(_.subGlobal,n.stpl))null==s||0===s&&n.start===n.end&&n.opt||!m(u)||(u=s<u.length?u[s]:null),f=null==u&&null!==n.dval?n.dval:(a=Q(l,n.stpl)?l[n.stpl].node:_.subGlobal[n.stpl].node,o={},null!=u&&(m(u)?o[a.name]=u:o=u),p(o,a,l,t,0,n.algn?i:"",null==r?e:r));else{if(c=null,Q(t,n.stpl)?c=t[n.stpl]:Q(t,"*")?c=t["*"]:Q(_.fnGlobal,n.stpl)?c=_.fnGlobal[n.stpl]:_.fnGlobal["*"]&&(c=_.fnGlobal["*"]),m(u)&&(u=(s=null!=s?s:n.start)<u.length?u[s]:null),"function"==typeof c)u=c(u,{symbol:n,index:s,currentArguments:e,originalArguments:r,alignment:i});else u=String(c);f=null==u&&null!==n.dval?n.dval:String(u),n.algn&&(f=d(f,i))}else n.opt&&null!==n.dval?f=n.dval:(m(u=T(e,n.key,[String(n.name)],n.loc?null:r))&&(u=(s=null!=s?s:n.start)<u.length?u[s]:null),f=null==u&&null!==n.dval?n.dval:String(u),n.algn&&(f=d(f,i)));return f}function v(e,n,l,t,s,i,r){for(var u,o=i=i||"",a="";n;)-1===(u=n.node.type)?a+=p(e,n.node,l,t,0,n.node.algn?o:i,r):1===u?a+=f(e,n.node,l,t,s,n.node.algn?o:i,r):0===u?(o+=n.node.algn,a+=n.node.val):100===u&&(a+="\n"+(o=i)),n=n.next;return a}function _(e,n,l){var t=this;if(!(t instanceof _))return new _(e,n,l);t.id=null,t.tpl=null,t.fn={},t._args=[e||"",n||_.defaultDelimiters,l||!1]}function h(e,n){return new RegExp(e,n||"")}function E(e){return e.replace(s,"\\$&")}function r(e){return"function"==typeof e}function I(e){return e instanceof String||"[object String]"===t.call(e)}function m(e){return e instanceof Array||"[object Array]"===t.call(e)}function b(e){return e instanceof Object||"[object Object]"===t.call(e)}function N(e){var n=t.call(e);return(e instanceof Array||e instanceof String||"[object Array]"===n||"[object String]"===n)&&!e.length||((e instanceof Object||"[object Object]"===n)&&!l(e).length||!e)}function A(e){return parseInt(e||0,10)||0}function O(e){return e===+e&&isFinite(e)&&!(e%1)}function R(e){return m(e)?e:[e]}function w(e,n,l){var t,s,i,r="";for(arguments.length<3&&(l="\\"),arguments.length<2&&(n="\\\"'"+o),t=0,s=e.length;t<s;t++)i=e[X](t),r+=-1===n.indexOf(i)?i:0===i[u](0)?"\\0":l+i;return r}function y(e,n,l,t){for(var s in l=!0===l,t=!0===t,n)g.call(n,s)&&(!l&&g.call(e,s)||(e[s]=t&&n[s].slice?n[s].slice():n[s]));return e}function L(e,n){var l=e.length;if(!l)return[];var t,s,i=15&l,r=1&i,u=new Array(l);for(r&&(u[0]=n(e[0])),t=r;t<i;t+=2)u[s=t]=n(e[s]),u[t+1]=n(e[s+1]);for(t=i;t<l;t+=16)u[s=t]=n(e[s]),u[t+1]=n(e[s+1]),u[t+2]=n(e[s+2]),u[t+3]=n(e[s+3]),u[t+4]=n(e[s+4]),u[t+5]=n(e[s+5]),u[t+6]=n(e[s+6]),u[t+7]=n(e[s+7]),u[t+8]=n(e[s+8]),u[t+9]=n(e[s+9]),u[t+10]=n(e[s+10]),u[t+11]=n(e[s+11]),u[t+12]=n(e[s+12]),u[t+13]=n(e[s+13]),u[t+14]=n(e[s+14]),u[t+15]=n(e[s+15]);return u}function S(e,n){var l=e.length;if(!l)return[];var t,s,i=15&l,r=1&i,u=[];for(r&&n(e[0])&&u.push(e[0]),t=r;t<i;t+=2)n(e[s=t])&&u.push(e[s]),n(e[++s])&&u.push(e[s]);for(t=i;t<l;t+=16)n(e[s=t])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]),n(e[++s])&&u.push(e[s]);return u}function q(e,n,l){var t,s,i="";if(e&&e.length)for(l=null==l?",":l,i=e[0][n],t=1,s=e.length;t<s;t++)i+=l+e[t][n];return i}function B(e,n,l,t,s,i,r,u,o,a,c){var f=this;if(f._col=e,f.col=n,f._tbl=l,f.tbl=t,f._dtb=s,f.dtb=i,f._alias=r,f._qualified=o,f.qualified=a,f.full=f.qualified,f._func=null==c?[]:c,f._func.length)for(var d=0,p=f._func.length;d<p;d++)f.full=f._func[d]+"("+f.full+")";null!=f._alias?(f.alias=u,f.aliased=f.full+" AS "+f.alias):(f.alias=f.full,f.aliased=f.full)}J.GUID=0,a.VERSION="1.0.0",a.defaultArgs=/\$(-?[0-9]+)/g,a.guid=J,a.multisplit=function(e,n,l){var t,s,i,r,u,o,a,c,f,d;for(t in l=!!l,o=[[1,e]],n)if(g.call(n,t)){for(c=[],s=l?n[t]:t,i=[0,n[t]],r=0,f=o.length;r<f;r++)if(1===o[r][0]){if(d=(a=o[r][1].split(s)).length,c.push([1,a[0]]),1<d)for(u=0;u<d-1;u++)c.push(i),c.push([1,a[u+1]])}else c.push(o[r]);o=c}return o},a.multisplit_re=function(e,n){n=n.global?n:new RegExp(n.source,n.ignoreCase?"gi":"g");for(var l,t=[],s=0;l=n.exec(e);)t.push([1,e.slice(s,n.lastIndex-l[0].length)]),t.push([0,l[1]?l[1]:l[0]]),s=n.lastIndex;return t.push([1,e.slice(s)]),t},a.arg=function(e,n){var l,t,s,i,r,u="args";if(arguments.length&&null!=e)for(i=(e=e.substr?e.length?e.split("."):[]:[e]).length,r=!(!n||!n.substr),l=0;l<i;l++)s=+(t=e[l]),isNaN(s)?u+='["'+t+'"]':(s<0&&(t=r?n+-s:u+".length-"+-s),u+="["+t+"]");return u},a.compile=function(e,n){var l,t,s,i,r=e.length;if(!0===n){for(i='"use strict"; return (',l=0;l<r;l++)t=e[l][0],s=e[l][1],i+=t?s:a.arg(s);i+=");"}else{for(i='"use strict"; var argslen=args.length; return (',l=0;l<r;l++)t=e[l][0],s=e[l][1],i+=t?"'"+s.replace(SQUOTE,"\\'").replace(NEWLINE,"' + \"\\n\" + '")+"'":" + String("+a.arg(s,"argslen")+") + ";i+=");"}return new Function("args",i)},a[n]={constructor:a,id:null,tpl:null,_parsed:!1,_args:null,_renderer:null,dispose:function(){var e=this;return e.id=null,e.tpl=null,e._parsed=null,e._args=null,e._renderer=null,e},fixRenderer:function(){var e=this;return e.render="function"==typeof e._renderer?e._renderer:e.constructor[n].render,e},parse:function(){var e=this;if(!1===e._parsed){e._parsed=!0;var n=e._args[0],l=e._args[1],t=e._args[2];e._args=null,e.tpl=l instanceof RegExp?a.multisplit_re(n,l):a.multisplit(n,l),!0===t&&(e._renderer=a.compile(e.tpl),e.fixRenderer())}return e},render:function(e){var n=this;if(e=e||[],!1===n._parsed&&(n.parse(),n._renderer))return n._renderer(e);var l,t,s,i=n.tpl,r=i.length,u=e.length,o="";for(l=0;l<r;l++)1===(t=i[l])[0]?o+=t[1]:(+(s=t[1])===s&&s<0&&(s=u+s),o+=e[s]);return o}},_.VERSION="3.0.0",_.defaultDelimiters=["<",">","[","]"],_.fnGlobal={},_.subGlobal={},_.guid=J,_.multisplit=function(e,n,l){var t,s,i,r,u,o,a,c,f,d,p,_,h,E,T,g,v,I,m,b,N,A,O,R,w,y,L=n[0],S=n[1],q=n[2],M=n[3],C=L.length,D=S.length,B=q.length,k=M.length,U="#"+M,G=null,F=0,j=0,Y=0,H=0,x=e.length,W=[L,C,S,D],P=[q,B,M,k],V=[null,0,null,0,null,0,null,0];for(l=!0===l,m={type:1,name:null,key:null,stpl:null,dval:null,opt:0,neg:0,algn:0,loc:0,start:0,end:0},N=f=new z({type:0,val:"",algn:""}),T={},g={},I=v=b=A=null,W[1]<W[3]&&(p=W[0],W[2]=W[0],W[0]=p,_=W[1],W[3]=W[1],W[1]=_),P[1]<P[3]&&(p=P[0],P[2]=P[0],P[0]=p,_=P[1],P[3]=P[1],P[1]=_),_=i=s=0;s<4&&i<4;)W[s+1]<P[i+1]?(V[_]=P[i],V[_+1]=P[i+1],i+=2):(V[_]=W[s],V[_+1]=W[s+1],s+=2),_+=2;for(;s<4;)V[_]=W[s],V[_+1]=W[s+1],s+=2,_+=2;for(;i<4;)V[_]=P[i],V[_+1]=P[i+1],i+=2,_+=2;for(a=null,p="",_=0;_<x;)if("\\"!==(c=e[X](_)))if(y=null,V[0]===e.substr(_,V[1])?y=V[0]:V[2]===e.substr(_,V[3])?y=V[2]:V[4]===e.substr(_,V[5])?y=V[4]:V[6]===e.substr(_,V[7])&&(y=V[6]),L===y)_+=C,p.length&&(0===f.node.type?f.node.val+=p:f=new z({type:0,val:p,algn:""},f)),p="";else if(S===y){if(_+=D,u=p,p="",-1<(o=u.indexOf("|"))?(G=u.slice(o+1),u=u.slice(0,o)):G=null,"?"===(c=l?_<x?e[X](_):"":u[X](0))||"*"===c)j=1,i="*"===c?-(s=1):s=0,l?(_+=1)<x&&"!"===e[X](_)?_+=F=1:F=0:u="!"===u[X](1)?(F=1,u.slice(2)):(F=0,u.slice(1));else if("{"===c){if(l){for(p="",h=_+1,E=x;h<E&&"}"!==e[X](h);)p+=e[X](h++);_=h+1}else{for(p="",h=1,E=u.length;h<E&&"}"!==u[X](h);)p+=u[X](h++);u=u.slice(h+1)}j=1<(p=p.split(",")).length?(s=(s=K(p[0])).length?0|+s:0,i=(i=K(p[1])).length?0|+i:-1,1):(i=s=(s=K(p[0])).length?0|+s:0,0),p="",F=0}else i=s=F=j=0;if(F&&null===G&&(G=""),"@"===(c=u[X](0))?(Y=1,u=u.slice(1)):Y=0,"."===(c=u[X](0))?(H=1,u=u.slice(1)):H=0,u=(r=-1<u.indexOf(":")?u.split(":"):[u,null])[0],r=r[1],t=-1<u.indexOf(".")?u.split("."):null,v&&!Q(g,v)&&(g[v]={}),":="+q===e.substr(_,2+B)&&(_+=2,I=r=r&&r.length?r:"grtpl--"+J(),v&&u.length&&(g[v][u]=r)),!u.length)continue;null==r&&v&&Q(g,v)&&Q(g[v],u)&&(r=g[v][u]),j&&!m.opt?(m.name=u,m.key=t,m.stpl=r,m.dval=G,m.opt=j,m.neg=F,m.algn=Y,m.loc=H,b=new Z(null,[u,t,F,m.start=s,m.end=i,j,H])):j?(s!==i&&m.start===m.end&&(m.name=u,m.key=t,m.stpl=r,m.dval=G,m.opt=j,m.neg=F,m.algn=Y,m.loc=H,m.start=s,m.end=i),b=new Z(b,[u,t,F,s,i,j,H])):j||null!==m.name||(m.name=u,m.key=t,m.stpl=r,m.dval=G,m.opt=0,m.neg=F,m.algn=Y,m.loc=H,b=new Z(null,[u,t,F,m.start=s,m.end=i,0,H])),0===f.node.type&&(f.node.algn=$(f.node.val,0,f.node.val.length)),f=new z({type:1,name:u,key:t,stpl:r,dval:G,opt:j,algn:Y,loc:H,start:s,end:i},f)}else if(q===y){if(_+=B,p.length&&(0===f.node.type?f.node.val+=p:f=new z({type:0,val:p,algn:""},f)),p="","#"===e[X](_)){for(h=_+1,E=x;h<E&&U!==e.substr(h,k+1);)p+=e[X](h++);_=h+k+1,0===f.node.type&&(f.node.algn=$(f.node.val,0,f.node.val.length)),f=new z({type:-100,val:p},f),p="";continue}a=new Z(a,[f,A,m,b,v,I]),I&&(v=I),m={type:1,name:I=null,key:null,stpl:null,dval:null,opt:0,neg:0,algn:0,loc:0,start:0,end:0},b=null,A=f=new z({type:0,val:"",algn:""})}else M===y?(_+=k,d=f,O=A,R=m,w=b,a?(f=a.value[0],A=a.value[1],m=a.value[2],b=a.value[3],v=a.value[4],I=a.value[5],a=a.prev):f=null,p.length&&(0===d.node.type?d.node.val+=p:d=new z({type:0,val:p,algn:""},d)),p="",I?(T[I]=new z({type:2,name:R.name,key:R.key,loc:R.loc,algn:R.algn,start:R.start,end:R.end,opt_args:null,tpl:O}),I=null):(0===f.node.type&&(f.node.algn=$(f.node.val,0,f.node.val.length)),f=new z({type:-1,name:R.name,key:R.key,loc:R.loc,algn:R.algn,start:R.start,end:R.end,opt_args:w,tpl:O},f))):"\n"===(c=e[X](_++))?(p.length&&(0===f.node.type?f.node.val+=p:f=new z({type:0,val:p,algn:""},f)),p="",0===f.node.type&&(f.node.algn=$(f.node.val,0,f.node.val.length)),f=new z({type:100,val:"\n"},f)):p+=c;else p+=_+1<x?e[X](_+1):"",_+=2;return p.length&&(0===f.node.type?f.node.val+=p:f=new z({type:0,val:p,algn:""},f)),0===f.node.type&&(f.node.algn=$(f.node.val,0,f.node.val.length)),[N,T]},_.align=d,_.main=v,_[n]={constructor:_,id:null,tpl:null,fn:null,_args:null,dispose:function(){var e=this;return e.id=null,e.tpl=null,e.fn=null,e._args=null,e},parse:function(){var e=this;return null===e.tpl&&null!==e._args&&(e.tpl=_.multisplit(e._args[0],e._args[1],e._args[2]),e._args=null),e},render:function(e){var n=this;return null===n.tpl&&n.parse(),_.main(null==e?{}:e,n.tpl[0],n.tpl[1],n.fn)}};var k=/\s/,U=/[0-9]/,G=/[a-z_]/i;B.parse=function(e,n){if(e instanceof B)return e;var l,t,s,i,r,u,o,a,c,f,d,p,_,h,E,T,g,v,I,m,b,N,A,O,R,w,y,L,S,q,M,C,D=["AS"];for(t=(e=K(e)).length,i=(s=[[]])[l=0],r=[],u=[],o="",E=d=0,m=g=T=p=a=null;l<t;)if("("!==(_=e.charAt(l++))||1!==l)if(0<E){if('"'===_||"`"===_||"'"===_||"["===_||"]"===_){if(T){if(T===_)if(v=('"'===_||"`"===_)&&n.qn[3]===_+_||"'"===_&&n.q[3]===_+_,I=('"'===_||"`"===_)&&n.qn[3]==="\\"+_||"'"===_&&n.q[3]==="\\"+_,v&&l<t&&_===e.charAt(l))l++;else if(I){if(b=!1,-1===n.e[1].indexOf("'\\'")||"'\\'"!==e.slice(g,l))for(N=l-2;0<=N&&"\\"===e.charAt(N);)b=!b,N--;b||(g=T=null)}else g=T=null}else T="["===_?"]":_,g=l-1;continue}if(T)continue;if("("===_){E++;continue}if(")"!==_)continue;if(--E<0){a=["paren",l];break}if(0!==E)continue;if(T){a=["quote",l];break}o=m=e.slice(0,l)}else{if('"'===_||"`"===_||"'"===_||"["===_||"]"===_){if(!p){if(o.length||"]"===_){a=["invalid",l];break}p="["===_?"]":_;continue}if(p===_){if(l<t&&_===e.charAt(l)){o+=_,l++;continue}if(!o.length){a=["invalid",l];break}i.unshift([1,o]),r.unshift(o),o="",p=null;continue}if(p){o+=_;continue}}if(p)o+=_;else if("*"===_){if(o.length){a=["invalid",l];break}i.unshift([10,"*"]),r.unshift(10)}else if("."===_){if(o.length&&(i.unshift([1,o]),r.unshift(o),o=""),!i.length||1!==i[0][0]){a=["invalid",l];break}i.unshift([0,"."]),r.unshift(0)}else if("("===_){if(d++,o.length&&(i.unshift([2,o]),u.unshift(o),o=""),!i.length||2!==i[0][0]&&1!==i[0][0]){a=["invalid",l];break}1===i[0][0]&&(i[0][0]=2,u.unshift(r.shift())),s.unshift([]),i=s[0]}else if(")"===_){if(d--,o.length&&(h=-1<D.indexOf(o.toUpperCase()),i.unshift([h?5:1,o]),r.unshift(h?5:o),o=""),s.length<2){a=["invalid",l];break}s[1].unshift([100,s.shift()]),i=s[0]}else{if(k.test(_)){o.length&&(h=-1<D.indexOf(o.toUpperCase()),i.unshift([h?5:1,o]),r.unshift(h?5:o),o="");continue}if(U.test(_)){if(!o.length){a=["invalid",l];break}o+=_}else{if(!G.test(_)){a=["invalid",l];break}o+=_}}}else E++;if(o.length&&(i.unshift([1,o]),r.unshift(o),o=""),a||!d&&!E||(a=["paren",t]),a||!p&&!T||(a=["quote",t]),a||1===s.length||(a=["invalid",t]),a)throw c=a[1]-1,"paren"==(f=a[0])?new TypeError('Dialect: Mismatched parentheses "'+e+'" at position '+c+"."):"quote"==f?new TypeError('Dialect: Mismatched quotes "'+e+'" at position '+c+"."):new TypeError('Dialect: Invalid character "'+e+'" at position '+c+".");return q="",C=(S=null)!=m?(3<=r.length&&5===r[1]&&"string"==typeof r[0]&&(S=r.shift(),q=n.quote_name(S),r.shift()),y=R=null,L=w="",M=A=m,O=m):(3<=r.length&&5===r[1]&&"string"==typeof r[0]&&(S=r.shift(),q=n.quote_name(S),r.shift()),A=null,O="",!r.length||"string"!=typeof r[0]&&10!==r[0]||(10===r[0]?(r.shift(),A=O="*"):(A=r.shift(),O=n.quote_name(A))),R=null,w="",2<=r.length&&0===r[0]&&"string"==typeof r[1]&&(r.shift(),R=r.shift(),w=n.quote_name(R)),y=null,L="",2<=r.length&&0===r[0]&&"string"==typeof r[1]&&(r.shift(),y=r.shift(),L=n.quote_name(y)),M=(y?y+".":"")+(R?R+".":"")+(A||""),(y?L+".":"")+(R?w+".":"")+(A?O:"")),new B(A,O,R,w,y,L,S,q,M,C,u)},B[n]={constructor:B,_func:null,_col:null,col:null,_tbl:null,tbl:null,_dtb:null,dtb:null,_alias:null,alias:null,_qualified:null,qualified:null,full:null,aliased:null,cloned:function(e,n,l){var t=this;return n=arguments.length?n||e:(e=t._alias,t.alias),null==l&&(l=t._func),new B(t._col,t.col,t._tbl,t.tbl,t._dtb,t.dtb,e,n,t._qualified,t.qualified,l)},dispose:function(){var e=this;return e._func=null,e._col=null,e.col=null,e._tbl=null,e.tbl=null,e._dtb=null,e.dtb=null,e._alias=null,e.alias=null,e._qualified=null,e.qualified=null,e.full=null,e.aliased=null,e}};function M(e){var n=this;if(arguments.length||(e="mysql"),!(n instanceof M))return new M(e);if(e&&g.call(M.aliases,e)&&(e=M.aliases[e]),!e||!M.dialects[e]||!M.dialects[e].clauses)throw new TypeError('Dialect: SQL dialect does not exist for "'+e+'"');n.clau=null,n.clus=null,n.tbls=null,n.cols=null,n.vews={},n.tpls={},n.db=null,n.escdb=null,n.escdbn=null,n.p="",n.type=e,n.clauses=M.dialects[n.type].clauses,n.q=M.dialects[n.type].quotes[0],n.qn=M.dialects[n.type].quotes[1],n.e=M.dialects[n.type].quotes[2]||["","","",""],n.clauses instanceof M.GrammarTemplate||(n.clauses=new M.GrammarTemplate(n.clauses),M.dialects[n.type].clauses=n.clauses)}return M.VERSION="1.3.0",M.dialects={mysql:{quotes:[["'","'","\\'","\\'"],["`","`","``","``"],["","","",""]],functions:{strpos:["POSITION(",2," IN ",1,")"],strlen:["LENGTH(",1,")"],strlower:["LCASE(",1,")"],strupper:["UCASE(",1,")"],trim:["TRIM(",1,")"],quote:["QUOTE(",1,")"],random:["RAND()"],now:["NOW()"]},types:{BINARY:"VARBINARY",SMALLINT:"TINYINT",MEDIUMINT:"MEDIUMINT",INT:"UNSIGNED INT",SIGNED_INT:"INT",BIGINT:"UNSIGNED BIGINT",SIGNED_BIGINT:"BIGINT",FLOAT:"FLOAT",DOUBLE:"DOUBLE",BOOL:"TINYINT",TIMESTAMP:"TIMESTAMP",DATETIME:"DATETIME",DATE:"DATE",TIME:"TIME",VARCHAR:"VARCHAR",TEXT:"TEXT",BLOB:"BLOB"},clauses:"[<?start_transaction_clause|>START TRANSACTION <type|>;][<?commit_transaction_clause|>COMMIT;][<?rollback_transaction_clause|>ROLLBACK;][<?transact_clause|>START TRANSACTION  <type|>;\n<statements>;[\n<*statements>;]\n[<?rollback|>ROLLBACK;][<?!rollback>COMMIT;]][<?create_clause|>[<?view|>CREATE VIEW <create_table> [(\n<?columns>[,\n<*columns>]\n)] AS <query>][<?!view>CREATE[ <?temporary|>TEMPORARY] TABLE[ <?ifnotexists|>IF NOT EXISTS] <create_table> [(\n<?columns>:=[<col:COL>:=[[[CONSTRAINT <?constraint> ]UNIQUE KEY <name|> <type|> (<?uniquekey>[,<*uniquekey>])][[CONSTRAINT <?constraint> ]PRIMARY KEY <type|> (<?primarykey>)][[<?!index>KEY][<?index|>INDEX] <name|> <type|> (<?key>[,<*key>])][CHECK (<?check>)][<?column> <type>[ <?!isnull><?isnotnull|>NOT NULL][ <?!isnotnull><?isnull|>NULL][ DEFAULT <?default_value>][ <?auto_increment|>AUTO_INCREMENT][ <?!primary><?unique|>UNIQUE KEY][ <?!unique><?primary|>PRIMARY KEY][ COMMENT '<?comment>'][ COLUMN_FORMAT <?format>][ STORAGE <?storage>]]][,\n<*col:COL>]]\n)][ <?options>:=[<opt:OPT>:=[[ENGINE=<?engine>][AUTO_INCREMENT=<?auto_increment>][CHARACTER SET=<?charset>][COLLATE=<?collation>]][, <*opt:OPT>]]][\nAS <?query>]]][<?alter_clause|>ALTER [<?view|>VIEW][<?!view>TABLE] <alter_table>\n<columns>[ <?options>]][<?drop_clause|>DROP [<?view|>VIEW][<?!view>[<?temporary|>TEMPORARY ]TABLE][ <?ifexists|>IF EXISTS] <drop_tables>[,<*drop_tables>]][<?union_clause|>(<union_selects>)[\nUNION[<?union_all|> ALL]\n(<*union_selects>)][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <offset|0>,<?count>]][<?select_clause|>SELECT <select_columns>[,<*select_columns>]\nFROM <from_tables>[,<*from_tables>][\n<?join_clauses>:=[<join:JOIN>:=[[<?type> ]JOIN <table>[ ON <?cond>]][\n<*join:JOIN>]]][\nWHERE <?where_conditions>][\nGROUP BY <?group_conditions>[,<*group_conditions>]][\nHAVING <?having_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <offset|0>,<?count>]][<?insert_clause|>INSERT INTO <insert_tables> (<insert_columns>[,<*insert_columns>])\n[VALUES <?values_values>[,<*values_values>]]][<?update_clause|>UPDATE <update_tables>\nSET <set_values>[,<*set_values>][\nWHERE <?where_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <offset|0>,<?count>]][<?delete_clause|>DELETE \nFROM <from_tables>[,<*from_tables>][\nWHERE <?where_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <offset|0>,<?count>]]"},postgresql:{quotes:[["'","'","''","''"],['"','"','""','""'],["E","","E",""]],functions:{strpos:["position(",2," in ",1,")"],strlen:["length(",1,")"],strlower:["lower(",1,")"],strupper:["upper(",1,")"],trim:["trim(",1,")"],quote:["quote(",1,")"],random:["random()"],now:["now()"]},types:{BINARY:"BYTEA",SMALLINT:"SMALLINT",MEDIUMINT:"INTEGER",INT:"SERIAL",SIGNED_INT:"INTEGER",BIGINT:"BIGSERIAL",SIGNED_BIGINT:"BIGINT",FLOAT:"REAL",DOUBLE:"DOUBLE PRECISION",BOOL:"BOOLEAN",TIMESTAMP:"TIMESTAMP WITHOUT TIME ZONE",DATETIME:"TIMESTAMP WITHOUT TIME ZONE",DATE:"DATE",TIME:"TIME WITHOUT TIME ZONE",VARCHAR:"VARCHAR",TEXT:"TEXT",BLOB:"BLOB"},clauses:"[<?start_transaction_clause|>START TRANSACTION <type|>;][<?commit_transaction_clause|>COMMIT;][<?rollback_transaction_clause|>ROLLBACK;][<?transact_clause|>START TRANSACTION  <type|>;\n<statements>;[\n<*statements>;]\n[<?rollback|>ROLLBACK;][<?!rollback>COMMIT;]][<?create_clause|>[<?view|>CREATE[ <?temporary|>TEMPORARY] VIEW <create_table> [(\n<?columns>[,\n<*columns>]\n)] AS <query>][<?!view>CREATE[ <?temporary|>TEMPORARY] TABLE[ <?ifnotexists|>IF NOT EXISTS] <create_table> [(\n<?columns>:=[<col:COL>:=[[<?column> <type>[ COLLATE <?collation>][ CONSTRAINT <?constraint>][ <?!isnull><?isnotnull|>NOT NULL][ <?!isnotnull><?isnull|>NULL][ DEFAULT <?default_value>][ CHECK (<?check>)][ <?unique|>UNIQUE][ <?primary|>PRIMARY KEY]]][,\n<*col:COL>]]\n)]]][<?alter_clause|>ALTER [<?view|>VIEW][<?!view>TABLE] <alter_table>\n<columns>[ <?options>]][<?drop_clause|>DROP [<?view|>VIEW][<?!view>TABLE][ <?ifexists|>IF EXISTS] <drop_tables>[,<*drop_tables>]][<?union_clause|>(<union_selects>)[\nUNION[<?union_all|> ALL]\n(<*union_selects>)][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <?count> OFFSET <offset|0>]][<?select_clause|>SELECT <select_columns>[,<*select_columns>]\nFROM <from_tables>[,<*from_tables>][\n<?join_clauses>:=[<join:JOIN>:=[[<?type> ]JOIN <table>[ ON <?cond>]][\n<*join:JOIN>]]][\nWHERE <?where_conditions>][\nGROUP BY <?group_conditions>[,<*group_conditions>]][\nHAVING <?having_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <?count> OFFSET <offset|0>]][<?insert_clause|>INSERT INTO <insert_tables> (<insert_columns>[,<*insert_columns>])\n[VALUES <?values_values>[,<*values_values>]]][<?update_clause|>UPDATE <update_tables>\nSET <set_values>[,<*set_values>][\nWHERE <?where_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <?count> OFFSET <offset|0>]][<?delete_clause|>DELETE \nFROM <from_tables>[,<*from_tables>][\nWHERE <?where_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <?count> OFFSET <offset|0>]]"},transactsql:{quotes:[["'","'","''","''"],["[","]","[","]"],[""," ESCAPE '\\'","",""]],functions:{strpos:["CHARINDEX(",2,",",1,")"],strlen:["LEN(",1,")"],strlower:["LOWER(",1,")"],strupper:["UPPER(",1,")"],trim:["LTRIM(RTRIM(",1,"))"],quote:["QUOTENAME(",1,',"\'")'],random:["RAND()"],now:["CURRENT_TIMESTAMP"]},types:{BINARY:"VARBINARY",SMALLINT:"TINYINT",MEDIUMINT:"SMALLINT",INT:"INT",SIGNED_INT:"INT",BIGINT:"BIGINT",SIGNED_BIGINT:"BIGINT",FLOAT:"FLOAT",DOUBLE:"REAL",BOOL:"BIT",TIMESTAMP:"DATETIME",DATETIME:"DATETIME",DATE:"DATE",TIME:"TIME",VARCHAR:"VARCHAR",TEXT:"TEXT",BLOB:"TEXT"},clauses:"[<?start_transaction_clause|>BEGIN TRANSACTION <type|>;][<?commit_transaction_clause|>COMMIT;][<?rollback_transaction_clause|>ROLLBACK;][<?transact_clause|>BEGIN TRANSACTION  <type|>;\n<statements>;[\n<*statements>;]\n[<?rollback|>ROLLBACK;][<?!rollback>COMMIT;]][<?create_clause|>[<?view|>CREATE[ <?temporary|>TEMPORARY] VIEW[ <?ifnotexists|>IF NOT EXISTS] <create_table> [(\n<?columns>[,\n<*columns>]\n)] AS <query>][<?!view>[<?ifnotexists|>IF NOT EXISTS (SELECT * FROM sysobjects WHERE name=<create_table> AND xtype='U')\n]CREATE TABLE <create_table> [<?!query>(\n<columns>:=[<col:COL>:=[[[CONSTRAINT <?constraint> ]<?column> <type|>[ <?isnotnull|>NOT NULL][ [CONSTRAINT <?constraint> ]DEFAULT <?default_value>][ CHECK (<?check>)][ <?!primary><?unique|>UNIQUE][ <?!unique><?primary|>PRIMARY KEY[ COLLATE <?collation>]]]][,\n<*col:COL>]]\n)][<?ifnotexists|>\nGO]]][<?alter_clause|>ALTER [<?view|>VIEW][<?!view>TABLE] <alter_table>\n<columns>[ <?options>]][<?drop_clause|>DROP [<?view|>VIEW][<?!view>TABLE][ <?ifexists|>IF EXISTS] <drop_tables>[,<*drop_tables>]][<?union_clause|>(<union_selects>)[\nUNION[<?union_all|> ALL]\n(<*union_selects>)][\nORDER BY <?order_conditions>[,<*order_conditions>]]][<?select_clause|>SELECT <select_columns>[,<*select_columns>]\nFROM <from_tables>[,<*from_tables>][\n<?join_clauses>:=[<join:JOIN>:=[[<?type> ]JOIN <table>[ ON <?cond>]][\n<*join:JOIN>]]][\nWHERE <?where_conditions>][\nGROUP BY <?group_conditions>[,<*group_conditions>]][\nHAVING <?having_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>][\nOFFSET <offset|0> ROWS FETCH NEXT <?count> ROWS ONLY]][<?!order_conditions>[\nORDER BY 1\nOFFSET <offset|0> ROWS FETCH NEXT <?count> ROWS ONLY]]][<?insert_clause|>INSERT INTO <insert_tables> (<insert_columns>[,<*insert_columns>])\n[VALUES <?values_values>[,<*values_values>]]][<?update_clause|>UPDATE <update_tables>\nSET <set_values>[,<*set_values>][\nWHERE <?where_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]]][<?delete_clause|>DELETE \nFROM <from_tables>[,<*from_tables>][\nWHERE <?where_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]]]"},sqlite:{quotes:[["'","'","''","''"],['"','"','""','""'],[""," ESCAPE '\\'","",""]],functions:{strpos:["instr(",2,",",1,")"],strlen:["length(",1,")"],strlower:["lower(",1,")"],strupper:["upper(",1,")"],trim:["trim(",1,")"],quote:["quote(",1,")"],random:["random()"],now:["datetime('now')"]},types:{BINARY:"BLOB",SMALLINT:"INTEGER",MEDIUMINT:"INTEGER",INT:"INTEGER",SIGNED_INT:"INTEGER",BIGINT:"INTEGER",SIGNED_BIGINT:"INTEGER",FLOAT:"REAL",DOUBLE:"REAL",BOOL:"INTEGER",TIMESTAMP:"TEXT",DATETIME:"TEXT",DATE:"TEXT",TIME:"TEXT",VARCHAR:"TEXT",TEXT:"TEXT",BLOB:"BLOB"},clauses:"[<?start_transaction_clause|>BEGIN <type|> TRANSACTION;][<?commit_transaction_clause|>COMMIT;][<?rollback_transaction_clause|>ROLLBACK;][<?transact_clause|>BEGIN <type|> TRANSACTION;\n<statements>;[\n<*statements>;]\n[<?rollback|>ROLLBACK;][<?!rollback>COMMIT;]][<?create_clause|>[<?view|>CREATE[ <?temporary|>TEMPORARY] VIEW[ <?ifnotexists|>IF NOT EXISTS] <create_table> [(\n<?columns>[,\n<*columns>]\n)] AS <query>][<?!view>CREATE[ <?temporary|>TEMPORARY] TABLE[ <?ifnotexists|>IF NOT EXISTS] <create_table> [<?!query>(\n<columns>:=[<col:COL>:=[[[CONSTRAINT <?constraint> ]<?column> <type|>[ <?isnotnull|>NOT NULL][ DEFAULT <?default_value>][ CHECK (<?check>)][ <?!primary><?unique|>UNIQUE][ <?!unique><?primary|>PRIMARY KEY[ <?auto_increment|>AUTOINCREMENT][ COLLATE <?collation>]]]][,\n<*col:COL>]]\n)[ <?without_rowid|>WITHOUT ROWID]][AS <?query>]]][<?alter_clause|>ALTER [<?view|>VIEW][<?!view>TABLE] <alter_table>\n<columns>[ <?options>]][<?drop_clause|>DROP [<?view|>VIEW][<?!view>TABLE][ <?ifexists|>IF EXISTS] <drop_tables>][<?union_clause|>(<union_selects>)[\nUNION[<?union_all|> ALL]\n(<*union_selects>)][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <?count> OFFSET <offset|0>]][<?select_clause|>SELECT <select_columns>[,<*select_columns>]\nFROM <from_tables>[,<*from_tables>][\n<?join_clauses>:=[<join:JOIN>:=[[<?type> ]JOIN <table>[ ON <?cond>]][\n<*join:JOIN>]]][\nWHERE <?where_conditions>][\nGROUP BY <?group_conditions>[,<*group_conditions>]][\nHAVING <?having_conditions>][\nORDER BY <?order_conditions>[,<*order_conditions>]][\nLIMIT <?count> OFFSET <offset|0>]][<?insert_clause|>INSERT INTO <insert_tables> (<insert_columns>[,<*insert_columns>])\n[VALUES <?values_values>[,<*values_values>]]][<?update_clause|>UPDATE <update_tables>\nSET <set_values>[,<*set_values>][\nWHERE <?where_conditions>]][<?delete_clause|>[<?!order_conditions><?!count>DELETE FROM <from_tables> [, <*from_tables>][\nWHERE <?where_conditions>]][DELETE FROM <from_tables> [, <*from_tables>] WHERE rowid IN (\nSELECT rowid FROM <from_tables> [, <*from_tables>][\nWHERE <?where_conditions>]\nORDER BY <?order_conditions> [, <*order_conditions>][\nLIMIT <?count> OFFSET <offset|0>]\n)][<?!order_conditions>DELETE FROM <from_tables> [, <*from_tables>] WHERE rowid IN (\nSELECT rowid FROM <from_tables> [, <*from_tables>][\nWHERE <?where_conditions>]\nLIMIT <?count> OFFSET <offset|0>\n)]]"}},M.aliases={mysqli:"mysql",mariadb:"mysql",sqlserver:"transactsql",postgres:"postgresql",postgre:"postgresql"},M.StringTemplate=a,M.GrammarTemplate=_,M.Ref=B,M[n]={constructor:M,clau:null,clus:null,tbls:null,cols:null,vews:null,tpls:null,db:null,escdb:null,escdbn:null,p:null,type:null,clauses:null,q:null,qn:null,e:null,dispose:function(){var e=this;return e.clau=null,e.clus=null,e.tbls=null,e.cols=null,e.vews=null,e.tpls=null,e.db=null,e.escdb=null,e.escdbn=null,e.p=null,e.type=null,e.clauses=null,e.q=null,e.qn=null,e.e=null,e},toString:function(){return this.sql()||""},driver:function(e){return arguments.length?(this.db=e||null,this):this.db},escape:function(e,n){return arguments.length<2&&(n=!1),arguments.length?(this.escdb=e&&r(e)?[e,!!n]:null,this):this.escdb},escapeId:function(e,n){return arguments.length<2&&(n=!1),arguments.length?(this.escdbn=e&&r(e)?[e,!!n]:null,this):this.escdbn},prefix:function(e){return arguments.length?(this.p=e&&e.length?e:"",this):this.p},reset:function(e){var n=this;return n.clus={},n.tbls={},n.cols={},n.clau=e,n},clear:function(){var e=this;return e.clau=null,e.clus=null,e.tbls=null,e.cols=null,e},subquery:function(){var e,n,l,t=this;return(e=new M(t.type)).driver(t.driver()).prefix(t.prefix()),n=t.escape(),l=t.escapeId(),n&&e.escape(n[0],n[1]),l&&e.escapeId(l[0],l[1]),e.vews=t.vews,e},sql:function(){var e,n=this,l="";return n.clau&&(e=y({},n.clus),g.call(n.clus,"select_columns")&&(e.select_columns=q(n.clus.select_columns,"aliased")),g.call(n.clus,"from_tables")&&(e.from_tables=q(n.clus.from_tables,"aliased")),g.call(n.clus,"insert_tables")&&(e.insert_tables=q(n.clus.insert_tables,"aliased")),g.call(n.clus,"insert_columns")&&(e.insert_columns=q(n.clus.insert_columns,"full")),g.call(n.clus,"update_tables")&&(e.update_tables=q(n.clus.update_tables,"aliased")),g.call(n.clus,"create_table")&&(e.create_table=q(n.clus.create_table,"full")),g.call(n.clus,"alter_table")&&(e.alter_table=q(n.clus.alter_table,"full")),g.call(n.clus,"drop_tables")&&(e.drop_tables=q(n.clus.drop_tables,"full")),g.call(n.clus,"where_conditions_required")&&(e.where_conditions=g.call(n.clus,"where_conditions")?"("+n.clus.where_conditions_required+") AND ("+n.clus.where_conditions+")":n.clus.where_conditions_required),g.call(n.clus,"having_conditions_required")&&(e.having_conditions=g.call(n.clus,"having_conditions")?"("+n.clus.having_conditions_required+") AND ("+n.clus.having_conditions+")":n.clus.having_conditions_required),e[n.clau+"_clause"]=1,l=n.clauses.render(e)||""),l},createView:function(e){var n=this;return e&&n.clau&&(n.vews[e]={clau:n.clau,clus:n.clus,tbls:n.tbls,cols:n.cols},g.call(n.vews[e].clus,"where_conditions")&&(n.vews[e].clus.where_conditions&&(n.vews[e].clus.where_conditions_required=n.vews[e].clus.where_conditions),delete n.vews[e].clus.where_conditions),g.call(n.vews[e].clus,"having_conditions")&&(n.vews[e].clus.having_conditions&&(n.vews[e].clus.having_conditions_required=n.vews[e].clus.having_conditions),delete n.vews[e].clus.having_conditions),n.clear()),n},useView:function(e){var n,l,t=this;if(n=t.clus.select_columns,e=t.vews[e],t.clus=y(t.clus,e.clus,!0,!0),t.tbls=y({},e.tbls,!0),t.cols=y({},e.cols,!0),n){l=[];for(var s=0,i=(n=t.refs(n,t.cols,!0)).length;s<i;s++)"*"===n[s].full?l=l.concat(t.clus.select_columns):l.push(n[s]);t.clus.select_columns=l}return t},dropView:function(e){return e&&g.call(this.vews,e)&&delete this.vews[e],this},prepareTpl:function(e){var n,l,t,s,i,r,u,o;return N(e)||(o=1===(s=(t=arguments).length)?!(u=r=i=null):2===s?(i=t[1],u=r=null,!1):3===s?(r=t[1],u=t[2],!(i=null)):(i=t[1],r=t[2],u=t[3],!1),n=h((r=r?E(r):"%")+"(([rlfds]:)?[0-9a-zA-Z_]+)"+(u=u?E(u):"%")),l=new M.StringTemplate(o?this.sql():i,n),this.tpls[e]={sql:l,types:null}),this},prepared:function(e,n){var l,t,s,i,r,u,o,a,c,f=this;if(N(e)||!g.call(f.tpls,e))return"";if(l=f.tpls[e].sql,null===(t=f.tpls[e].types)){for(l.parse(),t={},u=0,o=l.tpl.length;u<o;u++)0===(a=l.tpl[u])[0]&&(1<(c=a[1].split(":")).length?(t[c[1]]=c[0],l.tpl[u][1]=c[1]):(t[c[0]]="s",l.tpl[u][1]=c[0]));f.tpls[e].types=t}for(c in s={},n)if(g.call(n,c))switch(i=n[c],g.call(t,c)?t[c]:"s"){case"r":m(i)?s[c]=i.join(","):s[c]=i;break;case"l":s[c]=f.like(i);break;case"f":if(m(i))for(r=R(i),s[c]=B.parse(r[0],f).aliased,u=1,o=r.length;u<o;u++)s[c]+=","+B.parse(r[u],f).aliased;else s[c]=B.parse(i,f).aliased;break;case"d":m(i)?s[c]=f.intval(R(i)).join(","):s[c]=f.intval(i);break;case"s":default:m(i)?s[c]=f.quote(R(i)).join(","):s[c]=f.quote(i)}return l.render(s)},prepare:function(e,n,l,t){var s,i,r,u,o,a,c,f,d,p=this;if(e&&n){for(s=h((l=l?E(l):"%")+"([rlfds]:)?([0-9a-zA-Z_]+)"+(t=t?E(t):"%")),d="";e.length&&(i=e.match(s));){if(r=i.index,u=i[0].length,f=i[2],g.call(n,f)){switch(i[1]?i[1].slice(0,-1):"s"){case"r":f=m(n[f])?n[f].join(","):n[f];break;case"l":f=p.like(n[f]);break;case"f":if(m(n[f]))for(c=R(n[f]),f=B.parse(c[0],p).aliased,o=1,a=c.length;o<a;o++)f+=","+B.parse(c[o],p).aliased;else f=B.parse(n[f],p).aliased;break;case"d":f=m(n[f])?p.intval(R(n[f])).join(","):p.intval(n[f]);break;case"s":default:f=m(n[f])?p.quote(R(n[f])).join(","):p.quote(n[f])}d+=e.slice(0,r)+f}else d+=e.slice(0,r)+p.quote("");e=e.slice(r+u)}return e.length&&(d+=e),d}return e},dropTpl:function(e){return!N(e)&&g.call(this.tpls,e)&&(this.tpls[e].sql.dispose(),delete this.tpls[e]),this},StartTransaction:function(e,n){return n=n||"start_transaction",this.clau!==n&&this.reset(n),this.clus.type=e||null,this},CommitTransaction:function(e){return e=e||"commit_transaction",this.clau!==e&&this.reset(e),this},RollbackTransaction:function(e){return e=e||"rollback_transaction",this.clau!==e&&this.reset(e),this},Transaction:function(e,n){var l,t=this;return n=n||"transact",t.clau!==n&&t.reset(n),e=e||{},t.clus.type=e.type||null,t.clus.rollback=e.rollback?1:null,N(e.statements)||(l=R(l),t.clus.statements?t.clus.statements=t.clus.statements.concat(l):t.clus.statements=l),t},Create:function(e,n,l){var t,s,i=this;return l=l||"create",i.clau!==l&&i.reset(l),n=n||{ifnotexists:1},i.clus.create_table=i.refs(e,i.tbls),i.clus.view=n.view?1:null,i.clus.ifnotexists=n.ifnotexists?1:null,i.clus.temporary=n.temporary?1:null,i.clus.query=N(n.query)?null:n.query,N(n.columns)||(t=R(n.columns),i.clus.columns?i.clus.columns=i.clus.columns.concat(t):i.clus.columns=t),N(n.table)||(s=R(n.table),i.clus.options?i.clus.options=i.clus.options.concat(s):i.clus.options=s),i},Alter:function(e,n,l){var t,s,i=this;return l=l||"alter",i.clau!==l&&i.reset(l),i.clus.alter_table=i.refs(e,i.tbls),n=n||{},i.clus.view=n.view?1:null,N(n.columns)||(t=R(n.columns),i.clus.columns?i.clus.columns=i.clus.columns.concat(t):i.clus.columns=t),N(n.table)||(s=R(n.table),i.clus.options?i.clus.options=i.clus.options.concat(s):i.clus.options=s),i},Drop:function(e,n,l){var t,s=this;return l=l||"drop",s.clau!==l&&s.reset(l),t=m(e)?e[0]:e,g.call(s.vews,t)?s.dropView(t):(I(e)&&(e=e.split(",")),e=s.refs(null==e?"*":e,s.tbls),n=n||{ifexists:1},s.clus.view=n.view?1:null,s.clus.ifexists=n.ifexists?1:null,s.clus.temporary=n.temporary?1:null,s.clus.drop_tables?s.clus.drop_tables=s.clus.drop_tables.concat(e):s.clus.drop_tables=e),s},Select:function(e,n){var l=this;return n=n||"select",l.clau!==n&&l.reset(n),I(e)&&(e=e.split(",")),e=l.refs(null==e?"*":e,l.cols),l.clus.select_columns?l.clus.select_columns=l.clus.select_columns.concat(e):l.clus.select_columns=e,l},Union:function(e,n,l){var t=this;return l=l||"union",t.clau!==l&&t.reset(l),t.clus.union_selects?t.clus.union_selects=t.clus.union_selects.concat(R(e)):t.clus.union_selects=R(e),t.clus.union_all=n?"":null,t},Insert:function(e,n,l){var t,s=this;return l=l||"insert",s.clau!==l&&s.reset(l),t=m(e)?e[0]:e,g.call(s.vews,t)&&s.clau===s.vews[t].clau?s.useView(t):(I(e)&&(e=e.split(",")),I(n)&&(n=n.split(",")),e=s.refs(e,s.tbls),n=s.refs(n,s.cols),s.clus.insert_tables?s.clus.insert_tables=s.clus.insert_tables.concat(e):s.clus.insert_tables=e,s.clus.insert_columns?s.clus.insert_columns=s.clus.insert_columns.concat(n):s.clus.insert_columns=n),s},Values:function(e){var n,l,t,s,i,r,u,o,a=this;if(N(e))return a;for(c!==e[0]&&m(e[0])||(e=[e]),n=e.length,l=[],s=0;s<n;s++)if((o=R(e[s])).length){for(t=[],r=0,u=o.length;r<u;r++)b(i=o[r])?g.call(i,"raw")?t.push(i.raw):g.call(i,"integer")?t.push(a.intval(i.integer)):g.call(i,"string")&&t.push(a.quote(i.string)):t.push(null===i?"NULL":O(i)?i:a.quote(i));l.push("("+t.join(",")+")")}return l=l.join(","),a.clus.values_values&&(l=a.clus.values_values+","+l),a.clus.values_values=l,a},Update:function(e,n){var l,t=this;return n=n||"update",t.clau!==n&&t.reset(n),l=m(e)?e[0]:e,g.call(t.vews,l)&&t.clau===t.vews[l].clau?t.useView(l):(I(e)&&(e=e.split(",")),e=t.refs(e,t.tbls),t.clus.update_tables?t.clus.update_tables=t.clus.update_tables.concat(e):t.clus.update_tables=e),t},Set:function(e){var n,l,t,s,i,r,u=this;if(N(e))return u;for(t in n=[],r=u.cols,e)if(g.call(e,t))if(s=u.refs(t,r)[0].full,b(i=e[t])){if(g.call(i,"raw"))n.push(s+" = "+i.raw);else if(g.call(i,"integer"))n.push(s+" = "+u.intval(i.integer));else if(g.call(i,"string"))n.push(s+" = "+u.quote(i.string));else if(g.call(i,"increment"))n.push(s+" = "+s+" + "+u.intval(i.increment));else if(g.call(i,"decrement"))n.push(s+" = "+s+" - "+u.intval(i.increment));else if(g.call(i,"case")){if(l=s+" = CASE",g.call(i.case,"when")){for(case_value in i.case.when)g.call(i.case.when,case_value)&&(l+="\nWHEN "+u.conditions(i.case.when[case_value],!1)+" THEN "+u.quote(case_value));g.call(i.case,"else")&&(l+="\nELSE "+u.quote(i.case.else))}else for(case_value in i.case)g.call(i.case,case_value)&&(l+="\nWHEN "+u.conditions(i.case[case_value],!1)+" THEN "+u.quote(case_value));l+="\nEND",n.push(l)}}else n.push(s+" = "+(null===i?"NULL":O(i)?i:u.quote(i)));return n=n.join(","),u.clus.set_values&&(n=u.clus.set_values+","+n),u.clus.set_values=n,u},Delete:function(e){return e=e||"delete",this.clau!==e&&this.reset(e),this},From:function(e){var n,l=this;return N(e)||(n=m(e)?e[0]:e,g.call(l.vews,n)&&l.clau===l.vews[n].clau?l.useView(n):(I(e)&&(e=e.split(",")),e=l.refs(e,l.tbls),l.clus.from_tables?l.clus.from_tables=l.clus.from_tables.concat(e):l.clus.from_tables=e)),l},Join:function(e,n,l){var t,s,i,r=this;if(e=r.refs(e,r.tbls)[0].aliased,l=N(l)?null:l.toUpperCase(),N(n))t={table:e,type:l};else{if(I(n))n="("+(n=r.refs(n.split("="),r.cols))[0].full+"="+n[1].full+")";else{for(s in n)g.call(n,s)&&(b(i=n[s])||(n[s]={eq:i,type:"identifier"}));n="("+r.conditions(n,!1)+")"}t={table:e,type:l,cond:n}}return r.clus.join_clauses?r.clus.join_clauses.push(t):r.clus.join_clauses=[t],r},Where:function(e,n){var l=this;return N(e)||("OR"!==(n=n?n.toUpperCase():"AND")&&(n="AND"),e=l.conditions(e,!1),l.clus.where_conditions&&(e=l.clus.where_conditions+" "+n+" "+e),l.clus.where_conditions=e),l},Group:function(e){var n,l=this;return n=l.refs(e,l.cols)[0].alias,l.clus.group_conditions&&(n=l.clus.group_conditions+","+n),l.clus.group_conditions=n,l},Having:function(e,n){var l=this;return N(e)||("OR"!==(n=n?n.toUpperCase():"AND")&&(n="AND"),e=l.conditions(e,!0),l.clus.having_conditions&&(e=l.clus.having_conditions+" "+n+" "+e),l.clus.having_conditions=e),l},Order:function(e,n){var l,t=this;return"DESC"!==(n=n?n.toUpperCase():"ASC")&&(n="ASC"),l=t.refs(e,t.cols)[0].alias+" "+n,t.clus.order_conditions&&(l=t.clus.order_conditions+","+l),t.clus.order_conditions=l,t},Limit:function(e,n){return this.clus.count=A(e),this.clus.offset=A(n),this},Page:function(e,n){return e=A(e),n=A(n),this.Limit(n,e*n)},conditions:function(e,n){var l,t,s,i,r,u,o,a,c,f,d,p,_,h=this;if(N(e))return"";if(I(e))return e;for(s in l="",t=[],f=h.cols,u=!0===n?"alias":"full",e)if(g.call(e,s))if(b(r=e[s])){if(g.call(r,"raw")){t.push(String(r.raw));continue}if(g.call(r,"or")){d=[];for(var E=0,T=r.or.length;E<T;E++)p=r.or[E],d.push(h.conditions(p,n));t.push(d.join(" OR "));continue}if(g.call(r,"and")){d=[];for(E=0,T=r.and.length;E<T;E++)p=r.and[E],d.push(h.conditions(p,n));t.push(d.join(" AND "));continue}if(g.call(r,"either")){d=[];for(E=0,T=r.either.length;E<T;E++)(p={})[s]=r.either[E],d.push(h.conditions(p,n));t.push(d.join(" OR "));continue}if(g.call(r,"together")){d=[];for(E=0,T=r.together.length;E<T;E++)(p={})[s]=r.together[E],d.push(h.conditions(p,n));t.push(d.join(" AND "));continue}if(i=h.refs(s,f)[0][u],a=g.call(r,"type")?r.type:"string",g.call(r,"case")){if(d=i+" = CASE",g.call(r.case,"when")){for(_ in r.case.when)g.call(r.case.when,_)&&(d+=" WHEN "+h.conditions(r.case.when[_],n)+" THEN "+h.quote(_));g.call(r.case,"else")&&(d+=" ELSE "+h.quote(r.case.else))}else for(_ in r.case)g.call(r.case,_)&&(d+=" WHEN "+h.conditions(r.case[_],n)+" THEN "+h.quote(_));d+=" END",t.push(d)}else g.call(r,"multi_like")?t.push(h.multi_like(i,r.multi_like)):g.call(r,"like")?t.push(i+" LIKE "+("raw"===a?r.like:h.like(r.like))):g.call(r,"not_like")?t.push(i+" NOT LIKE "+("raw"===a?r.not_like:h.like(r.not_like))):g.call(r,"contains")?(c=String(r.contains),"raw"===a||(c=h.quote(c)),t.push(h.sql_function("strpos",[i,c])+" > 0")):g.call(r,"not_contains")?(c=String(r.not_contains),"raw"===a||(c=h.quote(c)),t.push(h.sql_function("strpos",[i,c])+" = 0")):g.call(r,"in")?(c=R(r.in),"raw"===a||(c="integer"===a||O(c[0])?h.intval(c):h.quote(c)),t.push(i+" IN ("+c.join(",")+")")):g.call(r,"not_in")?(c=R(r.not_in),"raw"===a||(c="integer"===a||O(c[0])?h.intval(c):h.quote(c)),t.push(i+" NOT IN ("+c.join(",")+")")):g.call(r,"between")?null==(c=R(r.between))[0]?("raw"===a||("integer"===a||O(c[1])?c[1]=h.intval(c[1]):c[1]=h.quote(c[1])),t.push(i+" <= "+c[1])):null==c[1]?("raw"===a||("integer"===a||O(c[0])?c[0]=h.intval(c[0]):c[0]=h.quote(c[0])),t.push(i+" >= "+c[0])):("raw"===a||(c="integer"===a||O(c[0])&&O(c[1])?h.intval(c):h.quote(c)),t.push(i+" BETWEEN "+c[0]+" AND "+c[1])):g.call(r,"not_between")?null==(c=R(r.not_between))[0]?("raw"===a||("integer"===a||O(c[1])?c[1]=h.intval(c[1]):c[1]=h.quote(c[1])),t.push(i+" > "+c[1])):null==c[1]?("raw"===a||("integer"===a||O(c[0])?c[0]=h.intval(c[0]):c[0]=h.quote(c[0])),t.push(i+" < "+c[0])):("raw"===a||(c="integer"===a||O(c[0])&&O(c[1])?h.intval(c):h.quote(c)),t.push(i+" < "+c[0]+" OR "+i+" > "+c[1])):g.call(r,"gt")||g.call(r,"gte")?(c=r[o=g.call(r,"gt")?"gt":"gte"],"raw"===a||(c="integer"===a||O(c)?h.intval(c):"identifier"===a||"field"===a?h.refs(c,f)[0][u]:h.quote(c)),t.push(i+("gt"===o?" > ":" >= ")+c)):g.call(r,"lt")||g.call(r,"lte")?(c=r[o=g.call(r,"lt")?"lt":"lte"],"raw"===a||(c="integer"===a||O(c)?h.intval(c):"identifier"===a||"field"===a?h.refs(c,f)[0][u]:h.quote(c)),t.push(i+("lt"===o?" < ":" <= ")+c)):g.call(r,"not_equal")||g.call(r,"not_eq")?(c=r[o=g.call(r,"not_eq")?"not_eq":"not_equal"],"raw"===a||null===c||(c="integer"===a||O(c)?h.intval(c):"identifier"===a||"field"===a?h.refs(c,f)[0][u]:h.quote(c)),t.push(null===c?i+" IS NOT NULL":i+" <> "+c)):(g.call(r,"equal")||g.call(r,"eq"))&&(c=r[o=g.call(r,"eq")?"eq":"equal"],"raw"===a||null===c||(c="integer"===a||O(c)?h.intval(c):"identifier"===a||"field"===a?h.refs(c,f)[0][u]:h.quote(c)),t.push(null===c?i+" IS NULL":i+" = "+c))}else i=h.refs(s,f)[0][u],t.push(null===r?i+" IS NULL":i+" = "+(O(r)?r:h.quote(r)));return t.length&&(l="("+t.join(") AND (")+")"),l},joinConditions:function(e,n){var l,t,s,i,r,u,o,a,c,f,d=0;for(l in n)g.call(n,l)&&(t=B.parse(l,this)._col,g.call(e,t)&&(s=n[l],r=e[t].table,u=e[t].id,o=e[t].join,a=e[t].join_id,c=o+ ++d,i={},g.call(e[t],"key")&&t!==e[t].key?i[c+"."+(f=e[t].key)]=t:f=t,g.call(e[t],"value")?i[c+"."+e[t].value]=s:i[c+"."+f]=s,this.Join(o+" AS "+c,r+"."+u+"="+c+"."+a,"inner").Where(i),delete n[l]));return this},refs:function(e,n,l){var t,s,i,r,u,o,a,c,f;if(!0===l)for(r=0,u=e.length;r<u;r++)c=(a=e[r]).alias,f=a.qualified,"*"!==(s=a.full)&&(g.call(n,c)?e[r]=n[c]:g.call(n,s)?(i=(t=n[s]).alias,t.full!==s&&i!==c&&i===s&&(t=t.cloned(a.alias),e[r]=n[c]=t)):g.call(n,f)?((t=n[f]).qualified!==f&&(t=n[t.qualified]),t=a.full!==a.alias?t.cloned(a.alias,null,a._func):t.cloned(null,t.alias,a._func),e[r]=n[t.alias]=t,t.alias===t.full||g.call(n,t.full)||(n[t.full]=t)):(n[c]=a,c===s||g.call(n,s)||(n[s]=a)));else for(o=R(e),e=[],r=0,u=o.length;r<u;r++)c=(a=B.parse(o[r],this)).alias,f=a.full,g.call(n,c)?a=n[c]:(n[c]=a,f===c||g.call(n,f)||(n[f]=a)),e.push(a);return e},tbl:function(e){if(m(e)){for(var n=0,l=e.length;n<l;n++)e[n]=this.tbl(e[n]);return e}return this.p+e},intval:function(e){if(m(e)){for(var n=0,l=e.length;n<l;n++)e[n]=this.intval(e[n]);return e}return parseInt(e,10)},quote_name:function(e,n){var l,t,s,i,r=this.qn,u=this.escdbn;if(n=!0===n,m(e)){for(l=0,t=e.length,s=new Array(t);l<t;l++)s[l]=this.quote_name(e[l],n);return s}if(e=String(e),n&&r[0]===e.slice(0,r[0].length)&&r[1]===e.slice(-r[1].length))return e;if(u)return u[1]?u[0](e):r[0]+u[0](e)+r[1];for(l=0,t=e.length,s="";l<t;l++)i=e.charAt(l),r[0]===i?s+=r[2]:r[1]===i?s+=r[3]:s+=i;return r[0]+s+r[1]},quote:function(e){var n,l=this,t=l.q,s=l.e,i=l.escdb;if(m(e)){for(var r=0,u=e.length,o=new Array(u);r<u;r++)o[r]=l.quote(e[r]);return o}return n=-1!==(e=String(e)).indexOf("\\"),i?i[1]?i[0](e):(n?s[2]:"")+t[0]+i[0](e)+t[1]+(n?s[3]:""):(n?s[2]:"")+t[0]+l.esc(e)+t[1]+(n?s[3]:"")},esc:function(e){var n,l,t,s,i,r,u=this;if(m(e)){for(l=0,t=e.length,r=new Array(t);l<t;l++)r[l]=u.esc(e[l]);return r}if(u.escdb&&!u.escdb[1])return u.escdb[0](e);for(i=u.q,n=o+"\\",r="",l=0,t=(e=String(e)).length;l<t;l++)s=e.charAt(l),i[0]===s?r+=i[2]:i[1]===s?r+=i[3]:r+=w(s,n,"\\");return r},esc_like:function(e){if(m(e)){for(var n=0,l=e.length,t=new Array(l);n<l;n++)t[n]=this.esc_like(e[n]);return t}return w(e,"_%","\\")},like:function(e){var n,l,t=this;if(m(e)){for(var s=0,i=e.length,r=new Array(i);s<i;s++)r[s]=t.like(e[s]);return r}return n=t.q,(l=t.escdb?["","","",""]:t.e)[0]+n[0]+"%"+t.esc_like(t.esc(e))+"%"+n[1]+l[1]},multi_like:function(e,n,l){var t,s,i,r,u,o,a;for(l=!1!==l,t=e+" LIKE ",s=n.split(","),l&&(s=S(L(s,K),Boolean)),r=0,u=s.length;r<u;r++){for(i=s[r].split("+"),l&&(i=S(L(i,K),Boolean)),o=0,a=i.length;o<a;o++)i[o]=t+this.like(i[o]);s[r]="("+i.join(" AND ")+")"}return s.join(" OR ")},sql_function:function(e,n){var l,t,s,i,r,u;if(!g.call(M.dialects[this.type].functions,e))throw new TypeError('Dialect: SQL function "'+e+'" does not exist for dialect "'+this.type+'"');for(e=M.dialects[this.type].functions[e],u=(n=null!=n?R(n):[]).length,l="",t=!1,s=0,i=e.length;s<i;s++)r=e[s],l+=t?0<r&&r<=u?n[r-1]:"":r,t=!t;return l},sql_type:function(e){if(e=String(e).toUpperCase(),!g.call(M.dialects[this.type].types,e))throw new TypeError('Dialect: SQL type "'+e+'" does not exist for dialect "'+this.type+'"');return M.dialects[this.type].types[e]}},M});

For more information send a message to info at phpclasses dot org.