# # ITSV GmbH # CCDB - Command and Control Database # # FILE: dquerymfile_flexloadtable # DESCRIPTION: DQUERY definition for query flexloadtable # @querytitle Lade Tabelle flexibel aus managed file @querydescription Flexibles Laden einer Tabelle aus einem Managed File @group DATAFILE @attributenames mfileid:mfileid:{{mfileidoptions}},tablename:string:{{tablenameoptions}} @mfileidoptions {"labeltext":"Ladedatei","typedesc":"ID des managed file, das in die Tabelle geladen werden soll"} @tablenameoptions {"labeltext":"Tabelle","typedesc":"Name der Tabelle, in die der Inhalt der Datei geladen werden soll"} @querytype function @function seqtrans.seqtrans ~query.tsteps # # <>: initialize # if (this.init_done) goto record_proper # # <>: initialize file info from inputresult # qexpression proc: { copycvars(this,"MFILEID,MFILETYPE,MFILEATTRIBS"); this.recstoprocess = this.inputresult.getRowCount(); this.ppfx = this.fname+"("+this.dataname+")"; this.tablename = this.query.tablename; let cc, cnam; this.fcols = {}; this.fnames = new Array(); for (let hi=0; hi>: get information about table to load # aexpression logger.debug("DB: "+aux.objTxt(db)); db.analyzeCCDBtable(this.tablename,{},this); result_varname descres post_qexpression proc: { if (this.descres.resulttype!='tabdesc') { this.errcoll.collect(null,"analyze table for "+this.query.tablename+" did not produce tabdesc",this.descres); break proc; } this.tcols = {}; this.tnames = new Array(); let cc, cnam; for (let ci=0; ci>: find table-specific or general MFILE with control information # pre_qexpression this.gcmfid = 'rwobj_loadflex'; this.scmfid = 'rwobj_loadflex'+this.tablename; sql select MFILEID,MFILEATTRIBS from CCMFILES where MFILETYPE='rwobj' and MFILEID in (::scmfid::,::gcmfid::) named_params gcmfid,scmfid result_varname cmfres post_qexpression this.cmfid = null; this.cmfattribs = null; for (let ri=0; ri>: check if control MFILE found # if (!this.cmfid) goto skip_cmf # # <>: load and compile control MFILE # aexpression objcomp.compileMfile(this.cmfid,this.loadcontrols,{},this); post_qexpression logger.debug("flexloadtable.UDBG.tablename="+this.tablename+".loadcontrols(from_mfile): "+aux.objTxt(this.loadcontrols)); if (this.loadcontrols[this.tablename]) { this.loadcontrol = this.loadcontrols[this.tablename]; } # # <>: init done # skip_cmf: qexpression this.init_done = true; # # <>: check if record shall be inserted # record_proper: pre_qexpression this.skip_record = false; if (this.loadcontrol._skip_condition) { if (this.loadcontrol._skip_condition.qexpression) { this.skip_record = eval(this.loadcontrol._skip_condition.qexpression); } } if (this.skip_record) this.recsskipped++; if (this.skip_record) goto record_done # # <>: determine if update or insert # pre_qexpression proc: { this.db_oper = "INSERT"; if (this.loadcontrol._keep_unique) { if (this.loadcontrol._keep_unique.check_sql) { this.check_sql = this.loadcontrol._keep_unique.check_sql; if (this.loadcontrol._keep_unique.pre_check) { eval(this.loadcontrol._keep_unique.pre_check); } } if (this.check_sql) { this.db_oper = "CHECK"; } else { this.errcoll.collect(null,"no check_sql specified in _keep_unique of loadcontrol for table "+this.tablename,this.loadcontrol); break proc; } } } goto do_@@db_oper@@ # # <>: check if record already there: execute check sql statement # do_CHECK: sql @@check_sql@@ named_params @@TLIST@@ result_varname checkres # # <>: check if record already there: check checkselect result # pre_qexpression this.db_oper = "INSERT"; if (this.loadcontrol._keep_unique.post_check) { eval(this.localcontrol._keep_unique.post_check); } else { if (this.checkres.getRowCount()>0) { this.db_oper = "UPDATE"; } } goto do_@@db_oper@@ # # <>: update existing record # do_UPDATE: pre_qexpression proc: { if (this.loadcontrol._keep_unique.update_sql) { this.update_sql = this.loadcontrol._keep_unique.update_sql; } else { this.errcoll.collect(null,"no update_sql specified in _keep_unique of loadcontrol",this.loadcontrol); break proc; } } sql @@update_sql@@ named_params @@TLIST@@ post_qexpression this.recsprocessed++; # # <>: update complete # goto record_done # # <>: insert one record # do_INSERT: pre_qexpression proc: { let cname, ctc, clc; for (let ci=0; ci>: insert done # goto record_done # # <>: skip record, nothing changed # do_SKIP: pre_qexpression this.recsskipped++; goto record_done # # <>: record done, check if last record # record_done: if (!this.is_last_record) goto done # # <>: finish up protocol # qexpression ppush(this,[this.ppfx+"_FINISHED","RECSTOPROCESS="+this.recstoprocess,"RECSPROCESSED="+this.recsprocessed,"RECS_SKIPPED="+this.recsskipped]); # # <>: end of record # done: end