#
#	action sequence for object action setKFOQSDBrepdefAttribute
#

#
# prepare action
#
qexpression
	copycvars(this,"action,objtype,attribute,key,value");

#
# check highest version already in database
#
sql 
	select MAX(version) from CCTEXTFRAG 
	where type='KFOQSDBREPDEF' and parent='KFOQSDBREPDEF' and ident=::key:: and child_index=::attribute::
named_params	key,attname
result_varname	prevres

#
# determine next higher version to be created
#
qexpression
	if (this.prevres.getRowCount()>0) {
		this.version = this.prevres.getCellValue(0,0) + 1;
	} else {
		this.version = 1
	}
	if (this.debug) logger.debug("setKFOQSDBrepdefAttribute.NEW_VERSION="+this.version);

#
# perform the update SQL
#
sql 
	update CCTEXTFRAG set data=::value::, version=::version::
	 where type='KFOQSDBREPDEF' and parent='KFOQSDBREPDEF' and ident=::key:: and child_index=::attribute:: "+
		   and MAX(version) and frag_index=1
named_params	key,attname,value

#
# finally, set chain query to re-display report type definition info after having performed the action
#
done:
qexpression this.query.chain_query = {dataname: "kforepdefinfo", reptype: this.key};