#
#		ITSV GmbH
#	CCDB - Command and Control Database
#
#	FILE:			dquerymfile_reconvallMVBRFAUSW.txt
#	DESCRIPTION:	DQUERY definition for DQUERY reconvallMVBRFAUSW
#					re-convert all marked dmvbrfausw-managed-files
#
@querytitle			Re-Konvertiere alle zu re-konvertierenden managed files für CCMVBRFAUSW
@querydescription	Re-Konvertiert alle mit "to_reconvert":"true" markierten managed files der MFILETYPE dmvbrfausw, indem sie zuerst entladen und dann wieder geladen werden.
					dadurch wird das korrekte encoding angewandt und Umlaute usw. richtig in die Datenbank geladen
#
@group				SVCLMVBRFAUSWDATALOAD
@querytype			function
@function			seqtrans.seqtrans
@sql_select			select mf.MFILEID, mf.MFILENAME, mf.MFILEATTRIBS, maf.TRAEGER as MAFILES_TRAEGER, maf.FTIMESTAMP as MAFILES_FTIMESTAMP
					  from CCMFILES mf
						left join SVCLMAFILES maf on maf.MFILEID=mf.MFILEID
					 where MFILETYPE='dmvbrfausw' and MFILEATTRIBS like '%"to_reconvert":true%'

~query.tsteps

#
# 
# <<TSTEPNUM:0>>:	initialize
#
qexpression
	proc: {
		copycvars(this,"MFILEID,MFILENAME,MFILEATTRIBS,MAFILES_TRAEGER,MAFILES_FTIMESTAMP");
		if (!this.init_done) {
			this.ppfx = this.fname+"("+this.dataname+")";
			this.filestoprocess = this.inputresult.getRowCount();
			this.filesprocessed = 0;
			ppush(this,[this.ppfx+"_STARTED","FILESTOPROCESS="+this.filestoprocess,"",""]);
		}
	}

#
# <<TSTEPNUM:1>>: unload current file
#
query.dataname		unloadMVBRFAUSW
query.mfileid		@@MFILEID@@
post_qexpression
	ppush(this,[this.ppfx+"_FILE_UNLOADED","PROCESSED_MFILEID="+this.MFILEID,"PROCESSED_MFILENAME="+this.MFILENAME,"\r\n<pre>\r\nUNLOAD_RESULT: "+aux.objTxt(this.stepresult)+"\r\n</pre>\r\n"]);

#
# <<TSTEPNUM:2>>: load current file again
#
query.dataname		LOADMVBRFAUSW
query.mfileid		@@MFILEID@@
post_qexpression
	ppush(this,[this.ppfx+"_FILE_RELOADED","PROCESSED_MFILEID="+this.MFILEID,"PROCESSED_MFILENAME="+this.MFILENAME,"\r\n<pre>\r\nLOAD_RESULT: "+aux.objTxt(this.stepresult)+"\r\n</pre>\r\n"]);

#
# <<TSTEPNUM:3>>:	one record processed, check if last
#
record_done:
if		(!this.is_last_record)
goto	done

#
# <<TSTEPNUM:4>>:	finish up protocol
#
qexpression
	ppush(this,[this.ppfx+"_FINISHED","FILESTOPROCESS="+this.filestoprocess,"FILESPROCESSED="+this.filesprocessed,""]);

#
# <<TSTEPNUM:5>>:	end
#
done:
end
