# # ITSV GmbH # CCDB - Command and Control Database # # FILE: dquerymfile_notepadBackend.txt # DESCRIPTION: DQUERY definition for DQUERY notepadBackend # @querytitle Notepad Backend @querydescription alle für das Notepad benötigten Backend-Aktivitäten @group API @attributenames notepadname:string:{{notepadnameoptions}},cellid:string:{{cellidoptions}},action:string:{{actionoptions}},data:string:{{dataoptions}},debug:noyes:{{debugoptions}} @notepadnameoptions { labeltext: "Notepad-Name", typedesc: "Name, unter dem das aktuelle Notepad in der CCDB-Datenbank (Tabelle CCTEXTFRAG) abgespeichert wird" } @cellidoptions { labeltext: "Cell-ID", typedesc: "ID der Anzeige-Zelle im Notepad, zu der die Aktion ausgeführt werden soll" } @actionoptions { labeltext: "Notepad-Backend-Aktion", typedesc: "Aktion, die durchgeführt werden soll: help listet mögliche Aktionen" } @dataoptions { labeltext: "Daten", typedesc: "Daten, die der Aktion als Parameter mit gegeben werden" } @debugoptions { labeltext: "Debug", typedesc: "wenn \"Ja\", dann werden Debug-Informationen in das CCDB-Logfile geschrieben", is_optional: true } @querytype function @function seqtrans.seqtrans ~query.tsteps # # <>: determine action sequence # pre_qexpression proc: { this.copyqvars("action,notepadname,cellid,data"); if (this.query.hasOwnProperty("debug")) { this.debug = this.query.debug; } else { this.debug = false; } this.actlab = "action_"+this.action; if (!this.labels[this.actlab]) { this.errcoll.collect(null, "Cannot execute Notepad backend action \""+this.action+"\","+ " seqtrans label \""+this.actlab+"\" does not exist.",{ action: this.action, data: this.data }); break proc; } } goto @@actlab@@ # # ============================================================================== # # <>: action sql # action_sql: helptext führe SQL aus aus, muss eine Objekt-Darstellung sein (JSON oder pure-javascript) pre_qexpression proc: { this.debug = false; this.aparams = {}; this.data = aux.populate({ template: this.data, data: this.aparams, adata: this, delimname: "double_hashes", dbg: this.debug }); if (this.debug) logger.debug(this.phead("sql.populated")+".data=\""+this.data+"\".aparams: "+aux.objTxt(this.aprams)); this.dataobject = aux.txtObjDecode(this.data); if (typeof(this.dataobject)=="string") { this.dataobject = { data: this.data }; } this.dataobject.aparams = this.aparams; if (!this.dataobject.sql) this.dataobject.sql = this.dataobject.data; if (!this.dataobject.sql) { this.errcoll.collect(null, "notepadBackend cannot execute SQL, decoded data object contains no SQL", this.dataobject); break proc; } this.actsql = this.dataobject.sql; if (this.dataobject.aparams.cfgname) { this.tstep.cfgname = this.dataobject.aparams.cfgname; } logger.debug(this.phead("notepad_actsql=\"")+this.actsql+"\""); } sql @@actsql@@ result_varname sqlres catch_errors true post_qexpression proc: { logger.debug(this.phead("notepad_sql_post: ")+aux.objTxt({ sqlres: this.sqlres})); if (this.sqlres && this.sqlres.error) { this.result = new aux.Result({resulttype: 'plain', body: "Fehler beim Ausführen von SQL-Statement:
"+aux.objTxt(this.sqlres.error)+"
" }); break proc; } if (this.sqlres && this.sqlres.resulttype && this.sqlres.resulttype=="dbresult") { if (this.debug) logger.debug(this.phead("SQL_DONE_DBRESULT")+".result: "+aux.objTxt(this.sqlres)); this.result = this.sqlres; } else { if (this.debug) logger.debug(this.phead("SQL_DONE_NO_DBRESULT")+".result: "+aux.objTxt(this.sqlres)); let rc = ( this.sqlres && this.sqlres.resulttype && this.sqlres.resulttype=='object' && this.sqlres.resultobject && this.sqlres.resultobject.hasOwnProperty("affectedRows"))?this.sqlres.resultobject.affectedRows:"FEHLER"; if (rc=="FEHLER") { logger.error(this.phead("SQL_ERROR")+".error_result: "+aux.objTxt(this.sqlres)); this.errcoll.collect(null,"notepadBackend Error: not-wellformed result executing SQL statement",this.sqlres); break proc; } this.result = new aux.Result({resulttype: 'plain', body: "
"+aux.objTxt(this.sqlres.resultobject)+"
"}); } } # # <>: action sql end # end # # ============================================================================== # # <>: action javascript # # pre_qexpression also provides hooks for the javascript fragment to access session-wide memory for this notepad in this.notepaddata # action_javascript: helptext führe javascript aus aus pre_qexpression proc: { logger.debug("NotepadBackend.action=javascript, data: "+aux.objTxt(this.data)); if (typeof(this.data)=="string") { this.dataobject = { data: this.data }; } else if ((this.data==null) || (this.data==undefined) || (typeof(this.data)=="null") || (typeof(this.data)=="undefined")){ this.dataobject = {}; } else if (typeof(this.data)=="object") { this.dataobject = this.data; } else { this.dataobject = { data: this.data }; } if (this.dataobject.js) { this.tstep.qexpression = this.dataobject.js; } else if (this.dataobject.javascript) this.tstep.qexpression = this.dataobject.javascript; } else { this.tstep.qexpression = "this.println(\"no valid javascript in \""+aux.objTxt(this.data)+"\");"; } this.tstep.qexpression = this.data; this.printdata = new Array(); this.print = function(what) { if (this.printdata.length<1) this.printdata.push(""); if (typeof(what)!='string') what = String(what); if (what.indexOf("\n")<0) { this.printdata[this.printdata.length-1] += String(what); } else { let sa = what.split("\n"); this.printdata[this.printdata.length-1] += sa[0]; for (let si=1; si"}); catch_errors true result_varname qres post_qexpression proc: { if (this.qres && this.qres.error) { this.result = new aux.Result({resulttype: 'plain', body: "Fehler beim Ausführen von javascript:
"+aux.objTxt(this.qres.error)+"
" }); break proc; } if (!this.qres && this.printdata.length>0) { let phtml = ""; for (let li=0; li\n"; } phtml += "\n"; this.qres = new aux.Result({resulttype: "plain", body: phtml}); } if (this.qres && this.qres.resulttype && this.qres.resulttype=="plain") { this.result = this.qres; } else if (this.qres && this.qres.resulttype && this.qres.resulttype=="dbresult") { this.result = this.qres; } else { /* logger.debug(this.phead("JS_DONE_NO_DBRESULT")+".result: "+aux.objTxt(this.qres)); */ this.result = new aux.Result({resulttype: 'plain', body: "
"+aux.objTxt(this.qres)+"
"}); } } # # <>: action javascript end # end # # ============================================================================== # # <>: action async_javascript # # execute an ASYNCHRONOUS javascript on the server # pre_qexpression also provides hooks for the javascript fragment to access session-wide memory for this notepad in this.notepaddata # action_async_javascript: helptext führe javascript aus asynchron aus pre_qexpression proc: { logger.debug("NotepadBackend.action=javascript, data: "+aux.objTxt(this.data)); this.tstep.aexpression = this.data; this.printdata = new Array(); this.print = function(what) { if (this.printdata.length<1) this.printdata.push(""); if (typeof(what)!='string') what = String(what); if (what.indexOf("\n")<0) { this.printdata[this.printdata.length-1] += String(what); } else { let sa = what.split("\n"); this.printdata[this.printdata.length-1] += sa[0]; for (let si=1; si"}); this(); catch_errors true result_varname qres post_qexpression proc: { if (this.qres && this.qres.error) { this.result = new aux.Result({resulttype: 'plain', body: "Fehler beim Ausführen von javascript:
"+aux.objTxt(this.qres.error)+"
" }); break proc; } if (!this.qres && this.printdata.length>0) { let phtml = ""; for (let li=0; li\n"; } phtml += "\n"; this.qres = new aux.Result({resulttype: "plain", body: phtml}); } if (this.qres && this.qres.resulttype && this.qres.resulttype=="plain") { this.result = this.qres; } else if (this.qres && this.qres.resulttype && this.qres.resulttype=="dbresult") { this.result = this.qres; } else { /* logger.debug(this.phead("JS_DONE_NO_DBRESULT")+".result: "+aux.objTxt(this.qres)); */ this.result = new aux.Result({resulttype: 'plain', body: "
"+aux.objTxt(this.qres)+"
"}); } } # # <>: action javascript end # end # # ============================================================================== # # <>: action query # action_query: helptext Rufe DQUERY auf pre_qexpression proc: { // this.debug = true; this.aparams = {}; if (this.debug) logger.debug(this.phead("query.unpopulated")+".data=\""+this.data+"\""); this.data = aux.populate({ template: this.data, data: this.aparams, adata: this, delimname: "double_hashes", dbg: this.debug }); if (this.debug) logger.debug(this.phead("query.populated")+".data=\""+this.data+"\".aparams: "+aux.objTxt(this.aparams)); this.qobject = aux.txtObjDecode(this.data); if (this.debug) { logger.debug(this.phead("query.txtDecode")+".qobject: "+aux.objTxt(this.qobject)); } if (this.qobject.error) { this.errcoll.collect(this.qobject.error,"Error parsing query-object",this.data); break proc; } if (typeof(this.qobject)=="string") { this.qobject = { data: this.data }; } if (!aux.objectIsEmpty(this.aparams)) aux.copyObject(this.qobject,this.aparams); this.tstep.query = aux.deepCopy(this.qobject); } query.dataname ***notepadBackend.query.UNDEFINED*** catch_errors true result_varname qres post_qexpression proc: { if (this.qres && this.qres.error) { this.result = new aux.Result({ resulttype: 'plain', body: "Fehler beim Ausführen von DQUERY:
" + 
						aux.objTxt({ error:			this.qres.error,
			                         query_result:	this.qres
			                      })+"
" }); break proc; } if (this.qres && this.qres.resulttype && this.qres.resulttype=="plain") { this.result = this.qres; } else if (this.qres && this.qres.resulttype && this.qres.resulttype=="dbresult") { this.result = this.qres; } else { /* logger.debug(this.phead("QUERY_DONE_NO_DBRESULT")+".result: "+aux.objTxt(this.qres)); */ this.result = new aux.Result({resulttype: 'plain', body: "
"+aux.objTxt(this.qres)+"
"}); } } # # <>: action query end # end # # ============================================================================== # # <>: action save, check if already saved under this name # action_save: helptext Speichere das Notepad unter dem Namen sql select type,ident,version,parent,child_index,frag_index from CCTEXTFRAG where type='CCDBNOTEPAD' and ident=::notepadname:: named_params notepadname result_varname dbres # # <>: determine if create or update # if (this.dbres.getRowCount()>0) goto action_save_update # # <>: action save create # pre_qexpression this.jsondata = JSON.stringify(this.data); sql insert into CCTEXTFRAG(type,ident,version,parent,child_index,frag_index,data) values('CCDBNOTEPAD',::notepadname::,0,'CCDBNOTEPADS',0,0,::jsondata::) named_params notepadname,jsondata result_varname dbres post_qexpression proc: { let rc = (this.dbres && this.dbres.resulttype && this.dbres.resulttype=='object' && this.dbres.resultobject && this.dbres.resultobject.affectedRows)?this.dbres.resultobject.affectedRows:"FEHLER"; if (rc=="FEHLER") { this.errcoll.collect(null,"Error not-wellformed result saving notepad CCTEXTFRAG record",this.dbres); break proc; } this.result = new aux.Result({resulttype: 'plain', body: "Notepad \""+this.notepadname+"\" neu angelegt, "+rc+" Datensätze verändert"}); } # # <>: action save create end # end # # <>: action save update # action_save_update: pre_qexpression this.jsondata = JSON.stringify(this.data); this.version = this.dbres.getCellValue(0,2); sql update CCTEXTFRAG set version=::version::+1,data=::jsondata:: where type='CCDBNOTEPAD' and ident=::notepadname:: named_params version,jsondata,notepadname result_varname dbres post_qexpression proc: { let rc = (this.dbres && this.dbres.resulttype && this.dbres.resulttype=='object' && this.dbres.resultobject && this.dbres.resultobject.affectedRows)?this.dbres.resultobject.affectedRows:"FEHLER"; if (rc=="FEHLER") { this.errcoll.collect(null,"Error not-wellformed result in updateing notepad CCTEXTFRAG record",this.dbres); break proc; } this.result = new aux.Result({resulttype: 'plain', body: "Notepad \""+this.notepadname+"\" geändert, "+rc+" Datensätze verändert"}); } # # <>: action save update end # end # # ============================================================================== # # <>: action load - load the notepad from the database # notpad is stored in CCTEXTFRAG with # - type = 'CCDBNOTEPAD' # - ident = # action_load: helptext Lade Notepad aus der CCDB (Tabelle CCTEXTFRAG, in Spalte "ident") sql select type,ident,version,parent,child_index,frag_index,data from CCTEXTFRAG where type='CCDBNOTEPAD' and ident=::notepadname:: named_params notepadname result_varname dbres post_qexpression proc: { if (this.dbres.getRowCount()<1) { this.errcoll.collect(null,"Error reading notepad for name \""+this.notepadname+"\", no data returned"); break proc; } this.result = new aux.Result({ resulttype: "transparent", res: aux.txtObjDecode(this.dbres.getCellValue(0,6)) }); } # # <>: action load end # end # # ============================================================================== # # <>: action help - return help information # action_help: helptext Gibt diesen Hilfetext aus qexpression let res = ""; let actstepnum; let actstep; for (labelname in this.labels) { if (labelname.startsWith("action_") { res += "* " + labelname; actstepnum = this.labels[labelname]; res += " - TSTEP #" + actstepnum; actstep = this.tsteps[actstepnum]; if (actstep.helptext) { res += " - " + actstep.helptext; } } } # # <>: action help end # end