heissepreise/site/alasql.js

48 lines
432 KiB
JavaScript
Raw Normal View History

//! AlaSQL v3.0.0 build: develop-4287740e | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
"use strict";!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.alasql=t()}(this,function(){function U(){return null}var F,e,t,s,_,P,q,G,j,V,B,H,n,J,Y,W,X,K,Q,z,Z,e1,t1,s1,n1,r1,a1,i1,o1,u1,l1,c1,h1,d1,f1,p1,b1,E1,g1,m1,T1,S1,A1,y1,r,a,i,o,u,l,c,v1,N1,O1,C1,h,d,R1,f,I1,w1,p,$1,x1,k1,b,E,g,L1,D1,M1,U1,m,T,S,A,y,v,N,O,C,R,I,F1,_1,P1,w,q1,G1,j1,$,x,V1,B1,H1,J1,Y1,W1,X1,K1,Q1,z1,Z1,e2,t2,s2,n2,r2,a2,i2,k,o2,u2,l2,c2,h2,d2,f2,p2,b2,E2,g2,m2,T2,S2,A2,y2,v2,N2,O2,C2,R2,I2,w2,$2,x2,k2,L2,D2,M2,U2,F2,_2,P2,q2,G2,j2,V2,B2,H2,J2,Y2,W2,X2,K2,Q2,z2,Z2,ee,te,se,ne,re,ae,ie,oe,ue,le,ce,he,de,fe,pe,be,Ee,ge,me,Te,Se,Ae,ye,ve,Ne,Oe,Ce,Re,Ie,we,$e,xe,ke,Le,De,Me,Ue,Fe,_e,Pe,qe,Ge,je,Ve,Be,He,Je,Ye,We,Xe,Ke,Qe,ze,Ze,et,tt,st,nt,rt,at,it,ot,ut,lt,ct,ht,dt,ft,pt,bt,Et,gt,mt,Tt,St,At,yt,vt,Nt,Ot,Ct,Rt,It,wt,$t,xt,kt,Lt,Dt,Mt,Ut,Ft,_t,Pt,qt,Gt,jt,Vt,Bt,Ht,Jt,Yt,Wt,Xt,Kt,Qt,zt,Zt,e3,t3,s3,n3,r3,a3,i3,o3,u3,l3,c3,h3,d3,f3,p3,b3,E3,g3,m3,T3,S3,A3,y3,v3,N3,O3,C3,R3,I3,w3,$3,x3,k3,L3,D3,M3,U3,F3,_3,P3,q3,G3,j3,V3,B3,H3,J3,Y3,W3,X3,K3,Q3,z3,Z3,e4,t4,s4,n4,r4,a4,i4,o4,u4,l4,c4,h4,d4,f4,p4,b4,E4,g4,m4,T4,S4,A4,y4,v4,N4,O4,C4,R4,I4,w4,$4,x4,k4,L4,D4,M4,U4,F4,_4,P4,q4,G4,j4,V4,B4,H4,J4,Y4,W4,X4,K4,Q4,z4,Z4,es,ts,ss,ns,rs,as,is,os,us,ls,cs,hs,ds,L=function(e,t,s,n){if(t=t||[],"function"==typeof importScripts||!L.webworker)return 0===arguments.length?new M.Select({columns:[new M.Column({columnid:"*"})],from:[new M.ParamValue({param:0})]}):1===arguments.length&&e.constructor===Array?L.promise(e):("function"==typeof t&&(n=s,s=t,t=[]),"object"!=typeof t&&(t=[t]),"string"==typeof e&&"#"===e[0]&&"object"==typeof document?e=document.querySelector(e).textContent:"object"==typeof e&&e instanceof HTMLElement?e=e.textContent:"function"==typeof e&&(e=e.toString(),e=(/\/\*([\S\s]+)\*\//m.exec(e)||["","Function given as SQL. Plese Provide SQL string or have a /* ... */ syle comment with SQL in the function."])[1]),L.exec(e,t,s,n));n=L.lastid++,L.buffer[n]=s,L.webworker.postMessage({id:n,sql:e,params:t})},fs=(L.version="3.0.0",L.build="develop-4287740e",L.debug=void 0,gn=[1,108],Sn=[1,107],y1=[10,310,606,767],r=[10,310,314,606,767],a=[1,115],i=[1,116],o=[1,117],u=[1,118],l=[1,119],c=[1,120],Gs=[130,357,414],v1=[1,128],N1=[1,127],O1=[1,135],C1=[1,165],h=[1,176],d=[1,179],R1=[1,174],f=[1,182],I1=[1,186],w1=[1,161],p=[1,183],$1=[1,170],x1=[1,172],k1=[1,175],b=[1,184],E=[1,201],g=[1,202],L1=[1,167],D1=[1,194],M1=[1,189],U1=[1,190],m=[1,195],T=[1,196],S=[1,197],A=[1,198],y=[1,199],v=[1,200],N=[1,203],O=[1,204],C=[1,177],R=[1,178],I=[1,180],F1=[1,181],_1=[1,187],P1=[1,193],w=[1,185],q1=[1,188],G1=[1,173],j1=[1,171],$=[1,192],x=[1,205],V1=[2,4,5],B1=[2,476],H1=[1,208],J1=[1,213],Y1=[1,222],W1=[1,218],X1=[10,72,78,93,98,118,128,162,168,169,183,198,232,249,251,310,314,606,767],K1=[2,4,5,10,72,76,77,78,112,115,116,118,122,123,124,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,145,146,148,149,150,152,154,156,162,164,166,168,169,170,171,172,173,175,183,185,187,198,244,245,284,285,286,287,288,289,290,291,310,314,424,428,606,767],Q1=[2,4,5,10,53,72,74,76,77,78,89,93,95,98,99,107,112,115,116,118,122,123,124,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,145,146,148,149,150,152,154,156,162,164,166,168,169,170,171,172,173,175,179,180,181,183,185,187,189,198,206,208,222,223,224,225,226,227,228,229,232,239,244,245,246,247,249,251,270,271,284,285,286,287,288,289,290,291,293,300,304,310,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,334,335,336,337,339,342,343,400,404,405,408,410,412,413,421,422,424,428,438,440,441,443,444,445,446,447,451,452,455,456,468,474,509,511,512,521,606,767],z1=[1,251],Z1=[1,258],e2=[1,267],t2=[1,272],s2=[1,271],n2=[2,4,5,10,72,77,78,93,98,107,118,128,131,132,137,143,145,149,152,154,156,162,168,169,179,180,181,183,198,232,244,245,249,251,269,270,274,275,277,284,285,286,287,288,289,290,291,293,294,295,296,297,298,299,300,301,302,303,306,307,310,314,316,321,424,428,606,767],r2=[2,162],a2=[1,283],i2=[10,74,78,310,314,509,606,767],k=[2,4,5,10,53,
${t} : ${t} == 'string' && typeof Number(${t}) == 'number' ? Number(${t}) :
typeof ${t} == 'boolean' ? Number(${t}) : 0,`:`'${n}':(${s})|| typeof ${s} == 'number' ?
${s} : ${s} == 'string' && typeof Number(${s}) == 'number' ? Number(${s}) :
typeof ${s} === 'boolean' ? Number(${s}) : 0,`:"FIRST"===e.aggregatorid||"LAST"===e.aggregatorid?"'"+n+"':"+s+",":"MIN"===e.aggregatorid?"funcid"in e.expression?`'${n}': (typeof ${t=r(e.expression)} == 'number' ? ${t} : typeof ${t} == 'object' ?
typeof Number(${t}) == 'number' && ${t}!== null? ${t} : null : null),`:`'${n}': (typeof ${s} == 'number' ? ${s} : typeof ${s} == 'object' ?
typeof Number(${s}) == 'number' && ${s}!== null? ${s} : null : null),`:"MAX"===e.aggregatorid?"funcid"in e.expression?`'${n}' : (typeof ${t=r(e.expression)} == 'number' ? ${t} : typeof ${t} == 'object' ?
typeof Number(${t}) == 'number' ? ${t} : null : null),`:`'${n}' : (typeof ${s} == 'number' ? ${s} : typeof ${s} == 'object' ?
typeof Number(${s}) == 'number' ? ${s} : null : null),`:"ARRAY"===e.aggregatorid?"'"+n+"':["+s+"],":"COUNT"===e.aggregatorid?"*"===e.expression.columnid?"'"+n+"':1,":"'"+n+"':(typeof "+s+' == "undefined" || '+s+" === null) ? 0 : 1,":"AVG"===e.aggregatorid?(i.removeKeys.push("_SUM_"+n),i.removeKeys.push("_COUNT_"+n),"'"+n+"':"+s+",'_SUM_"+n+"':("+s+")||0,'_COUNT_"+n+"':(typeof "+s+' == "undefined" || '+s+" === null) ? 0 : 1,"):"AGGR"===e.aggregatorid?(a+=",g['"+n+"']="+e.expression.toJS("g",-1),""):"REDUCE"===e.aggregatorid?(i.aggrKeys.push(e),"'"+n+"':alasql.aggr['"+e.funcid+"']("+s+",undefined,1),"):""):""}).join(""))+"}"+a+",g));"+e+"} else {")+i.selectGroup.map(function(e){var t,s,n,r=e.nick,a=e.expression.toJS("p",o,u),i=e=>{return e.args[0].toJS("p",o,u)};return e instanceof M.AggrValue?(s=t="",e.distinct&&(t="if(typeof "+a+'!="undefined" && (!g[\'$$_VALUES_'+r+"']["+a+"])) {",s="g['$$_VALUES_"+r+"']["+a+"]=true;}"),"SUM"===e.aggregatorid?"funcid"in e.expression?t+`if(g['${r}'] == null && ${n=i(e.expression)} == null){g['${r}'] = null}
else if(typeof g['${r}']!== 'object' && typeof g['${r}']!== 'number' && typeof ${n}!== 'object' && typeof ${n}!== 'number'){g['${r}'] = null}
else if(typeof g['${r}']!== 'object' && typeof g['${r}']!== 'number' && typeof ${n} == 'number'){g['${r}'] = ${n}}
else if(typeof g['${r}']!== 'number' && typeof ${n}!== 'number' && typeof ${n}!== 'object'){g['${r}'] = g['${r}']}
else if((g['${r}'] == null || (typeof g['${r}']!== 'number' && typeof g['${r}']!== 'object')) && (${n} == null || (typeof ${n}!== 'number' && typeof ${n}!== 'object'))){g['${r}'] = null}
else if(typeof g['${r}'] == 'number' && typeof ${n} ==null){g['${r}'] = g['${r}']}
else if(typeof g['${r}'] == null && typeof ${n} =='number'){g['${r}'] = ${n}}
else{g['${r}'] += ${n}||0}`+s:t+`if(g['${r}'] == null && ${a} == null){g['${r}'] = null}
else if(typeof g['${r}']!== 'object' && typeof g['${r}']!== 'number'&& typeof ${a}!== 'object' && typeof ${a}!== 'number'){g['${r}'] = null}
else if(typeof g['${r}']!== 'object' && typeof g['${r}']!== 'number' && typeof ${a} == 'number'){g['${r}'] = ${a}}
else if(typeof g['${r}']!== 'number' && typeof ${a}!== 'number' && typeof ${a}!== 'object'){g['${r}'] = g['${r}']}
else if((g['${r}'] == null || (typeof g['${r}']!== 'number' && typeof g['${r}']!== 'object')) && (${a} == null || (typeof ${a}!== 'number' && typeof ${a}!== 'object'))){g['${r}'] = null}
else if(typeof g['${r}'] == 'number' && typeof ${a} ==null){g['${r}'] = g['${r}']}
else if(typeof g['${r}'] == null && typeof ${a} =='number'){g['${r}'] = ${a}}
else{g['${r}'] += ${a}||0}`+s:"TOTAL"===e.aggregatorid?"funcid"in e.expression?t+`if(typeof g['${r}'] == 'string' && !isNaN(g['${r}']) && typeof Number(g['${r}']) == 'number' &&
typeof ${n=i(e.expression)} == 'string' && !isNaN(${n}) && typeof Number(${n}) == 'number'){g['${r}'] = Number(g['${r}']) + Number(${n})}
else if(typeof g['${r}'] == 'string' && typeof ${n} == 'string'){g['${r}'] = 0}
else if(typeof g['${r}'] == 'string' && typeof ${n} == 'number'){g['${r}'] = ${n}}
else if(typeof ${n} == 'string' && typeof g['${r}'] == 'number'){g['${r}'] = g['${r}']}
else{g['${r}'] += ${n}||0}`+s:t+`if(typeof g['${r}'] == 'string' && !isNaN(g['${r}']) && typeof Number(g['${r}']) == 'number' &&
typeof ${a} == 'string' && !isNaN(${a}) && typeof Number(${a}) == 'number'){g['${r}'] = Number(g['${r}']) + Number(${a})}
else if(typeof g['${r}'] == 'string' && typeof ${a} == 'string'){g['${r}'] = 0}
else if(typeof g['${r}'] == 'string' && typeof ${a} == 'number'){g['${r}'] = ${a}}
else if(typeof ${a} == 'string' && typeof g['${r}'] == 'number'){g['${r}'] = g['${r}']}
else{g['${r}'] += ${a}||0}`+s:"COUNT"===e.aggregatorid?"*"===e.expression.columnid?t+"g['"+r+"']++;"+s:t+"if(typeof "+a+'!="undefined" && '+a+" !== null) g['"+r+"']++;"+s:"ARRAY"===e.aggregatorid?t+"g['"+r+"'].push("+a+");"+s:"MIN"===e.aggregatorid?"funcid"in e.expression?t+`if((g['${r}'] == null && ${n=i(e.expression)}!== null) ? y = ${n} : (g['${r}']!== null &&
${n} == null) ? y = g['${r}']:((y=${n}) < g['${r}'])){ if(typeof y == 'number')
{g['${r}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${r}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${r}'] = Number(y);}}
else if(g['${r}']!== null && typeof g['${r}'] == 'object' && y instanceof Date){g['${r}'] = g['${r}']}
else if(g['${r}']!== null && typeof g['${r}'] == 'object'){g['${r}'] = Number(g['${r}'])}`+s:t+`if((g['${r}'] == null && ${a}!== null) ? y = ${a} : (g['${r}']!== null &&
${a} == null) ? y = g['${r}']:((y=${a}) < g['${r}'])){ if(typeof y == 'number')
{g['${r}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${r}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${r}'] = Number(y);}}
else if(g['${r}']!== null && typeof g['${r}'] == 'object' && y instanceof Date){g['${r}'] = g['${r}']}
else if(g['${r}']!== null && typeof g['${r}'] == 'object'){g['${r}'] = Number(g['${r}'])}`+s:"MAX"===e.aggregatorid?"funcid"in e.expression?t+`if((y=${i(e.expression)}) > g['${r}']){if(typeof y == 'number'){g['${r}'] = y;}
else if(typeof y == 'object' && y instanceof Date){g['${r}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${r}'] = Number(y);}}`+s:t+`if((y=${a}) > g['${r}']){if(typeof y == 'number'){g['${r}'] = y;}
else if(typeof y == 'object' && y instanceof Date){g['${r}'] = y;}
else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${r}'] = Number(y);}}`+s:"FIRST"===e.aggregatorid?"":"LAST"===e.aggregatorid?t+"g['"+r+"']="+a+";"+s:"AVG"===e.aggregatorid?t+"g['_SUM_"+r+"']+=(y="+a+")||0;g['_COUNT_"+r+"']+=(typeof y == \"undefined\" || y === null) ? 0 : 1;g['"+r+"']=g['_SUM_"+r+"']/g['_COUNT_"+r+"'];"+s:"AGGR"===e.aggregatorid?t+"g['"+r+"']="+e.expression.toJS("g",-1)+";"+s:"REDUCE"===e.aggregatorid?t+"g['"+r+"']=alasql.aggr."+e.funcid+"("+a+",g['"+r+"'],2);"+s:""):""}).join("")+"}"}),new Function("p,params,alasql","var y;"+n)},M.Select.prototype.compileSelect1=function(a,i){var o=this,e=(a.columns=[],a.xcolumns={},a.selectColumns={},a.dirtyColumns=!1,"var r={"),u="",l=[];return this.columns.forEach(function(e){if(e instanceof M.Column)if("*"===e.columnid)e.func?u+="r=params['"+e.param+"'](p['"+a.sources[0].alias+"'],p,params,alasql);":(e.tableid?(t=Qs(a,[e.tableid],!1)).s&&(l=l.concat(t.s)):(t=Qs(a,Object.keys(a.aliases),!0)).s&&(l=l.concat(t.s)),u+=t.sp);else{var t=e.tableid,s=e.databaseid||a.sources[0].databaseid||a.database.databaseid;if(t=(t=t||a.defcols[e.columnid])||a.defaultTableid,"_"!==e.columnid?i&&1<i.length&&Array.isArray(i[0])&&1<=i[0].length&&i[0][0].hasOwnProperty("sheetid")?u='var r={};var w=p["'+t+'"];var cols=['+o.columns.map(function(e){return"'"+e.columnid+"'"}).join(",")+"];var colas=["+o.columns.map(function(e){return"'"+(e.as||e.columnid)+"'"}).join(",")+"];for (var i=0;i<Object.keys(p['"+t+"']).length;i++) for(var k=0;k<cols.length;k++){if (!r.hasOwnProperty(i)) r[i]={}; r[i][colas[k]]=w[i][cols[k]];}":l.push("'"+Ss(e.as||e.columnid)+"':p['"+t+"']['"+e.columnid+"']"):l.push("'"+Ss(e.as||e.columnid)+"':p['"+t+"']"),a.selectColumns[Ss(e.as||e.columnid)]=!0,a.aliases[t]&&"table"===a.aliases[t].type){if(!L.databases[s].tables[a.aliases[t].tableid])throw new Error("Table '"+t+"' does not exist in database");var n=L.databases[s].tables[a.aliases[t].tableid].columns,s=L.databases[s].tables[a.aliases[t].tableid].xcolumns;if(s&&0<n.length){t=s[e.columnid];if(void 0===t)throw new Error("Column does not exist: "+e.columnid);var r={columnid:e.as||e.columnid,dbtypeid:t.dbtypeid,dbsize:t.dbsize,dbpecision:t.dbprecision,dbenum:t.dbenum};a.columns.push(r),a.xcolumns[r.columnid]=r}else{var r={columnid:e.as||e.columnid};a.columns.push(r),a.xcolumns[r.columnid]=r,a.dirtyColumns=!0}}else{var r={columnid:e.as||e.columnid};a.columns.push(r),a.xcolumns[r.columnid]=r}}else r=(e instanceof M.AggrValue?(o.group||(o.group=[""]),e.as||(e.as=Ss(e.toString())),"SUM"===e.aggregatorid||"MAX"===e.aggregatorid||"MIN"===e.aggregatorid||"FIRST"===e.aggregatorid||"LAST"===e.aggregatorid||"AVG"===e.aggregatorid||"ARRAY"===e.aggregatorid||"REDUCE"===e.aggregatorid||"TOTAL"===e.aggregatorid?l.push("'"+Ss(e.as)+"':"+Es(e.expression.toJS("p",a.defaultTableid,a.defcols))):"COUNT"===e.aggregatorid&&l.push("'"+Ss(e.as)+"':1")):(l.push("'"+Ss(e.as||e.columnid||e.toString())+"':"+Es(e.toJS("p",a.defaultTableid,a.defcols))),a.selectColumns[Ss(e.as||e.columnid||e.toString())]=!0),{columnid:e.as||e.columnid||e.toString()}),a.columns.push(r),a.xcolumns[r.columnid]=r}),e+=l.join(",")+"};"+u},M.Select.prototype.compileSelect2=function(s,n){var r=s.selectfns;return this.orderColumns&&0<this.orderColumns.length&&this.orderColumns.forEach(function(e,t){t="$$$"+t;e instanceof M.Column&&s.xcolumns[e.columnid]?r+="r['"+t+"']=r['"+e.columnid+"'];":e instanceof M.ParamValue&&s.xcolumns[n[e.param]]?r+="r['"+t+"']=r['"+n[e.param]+"'];":r+="r['"+t+"']="+e.toJS("p",s.defaultTableid,s.defcols)+";",s.removeKeys.push(t)}),new Function("p,params,alasql","var y;"+r+"return r")},M.Select.prototype.compileSelectGroup0=function(a){var i=this;i.columns.forEach(function(t,e){if(t instanceof M.Column&&"*"===t.columnid)a.groupStar=t.tableid||"default";else{for(var s,n=t instanceof M.Column?Ss(t.columnid):Ss(t.toString(!0)),r=0;r<e;r++)if(n===i.columns[r].nick){n=i.columns[r].nick+":"+e;break}t.nick=n,i.group&&-1<(s=i.group.findIndex(function(e){return e.columnid===t.columnid&&e.tableid===t.tableid}))&&(i.group[s].nick=n),!t.funci