#
#		ITSV GmbH
#		CCDB - Command and Control Database
#
#	FILE:			dquerymfile_addLSW.txt
#	DESCRIPTION:	DQUERY definitions for DQUERY addLSW
#					this DQUERY adds a new LSW record in SVCLRWLSW
#
@querytitle			neue Lohnsoftware hinzufügen
@querydescription	speichert eine neue Lohnsoftware durch ihren Eintrag in der Tabelle SVCLRWLSW
@group				SVCLEARRW
@attributenames		LSWID:LSWID,LSWHID:LSWHID,LSWATTRIBS:string:{{lswattribsoptions}}
@lswattribsoptions	{"labeltext":"LSW-Attribute","typedesc":"Attribute der Lohnsoftware in JSON-Format"}
@querytype			function
@function			seqtrans.seqtrans
@sql_select			select '{{LSWID}}' as LSWID,'{{LSWHID}}' as LSWHID,'{{LSWATTRIBS}}' as LSWATTRIBS

~query.tsteps

#
# <<TSTEPNUM:0>>: initialize
#
qexpression
	proc: {
		copycvars(this,"LSWID,LSWHID,LSWATTRIBS");
		if (!this.init_done) {
			this.ppfx = this.fname+"("+this.dataname+")";
			this.init_done = true;
		}
		ppush(this,[this.ppfx+"_START_ADD_LSW","LSWID="+this.LSWID,"LSWHID="+this.LSWHID,"LSWATTRIBS="+this.LSWATTRIBS]);
	}

#
# <<TSTEPNUM:1>>: check if LSWID already known, if already there, abort adding new
#
sql				select LSWID,LSWHID,LSWATTRIBS from SVCLRWLSW where LSWID=::LSWID::
named_params	LSWID
result_varname	chkres
post_qexpression
	if (this.chkres.getRowCount()>0) {
		this.errcoll.collect(null,"LSWID \""+this.LSWID+"\" already known",this.cdata);
	}

#
# <<TSTEPNUM:2>>: create new entry
#
sql				insert into SVCLRWLSW(LSWID,LSWHID,LSWATTRIBS) values(::LSWID::,::LSWHID::,::LSWATTRIBS::)
named_params	LSWID,LSWHID,LSWATTRIBS
result_varname	insres
post_qexpression
	ppush(this,[this.ppfx+"_CREATED","AFFECTED_ROWS="+this.insres.resultobject.affectedRows,"DB_MESSAGE=\""+this.insres.resultobject.message+"\"","<dt>INSRES</dt><dd><pre>"+aux.objTxt(this.insres)+"</pre></dd>"]);
 