dmSQL1 ; hulp-functies bij queries ; dmSQL1 ; YZ Q ; FR(query,scr,ref,head) ; uitvoeren query ; query = SQL-statement ; scr = 1 ; schrijf resultaat op scherm ; ref = bestand waarin het resultaat terechtkomt (indien ingevuld) ; door te geven als "^bestand($j,...)" ; head = 1 ; moet de header op het scherm (of in bestand) geschreven worden ; ; uitgang : 0_"\"_errorcode ; 1_"\"_aantal records ; N N S N="(query,scr,ref,head" s:$e($g(ref))'="^"&$l($g(ref)) N=N_","_ref s N=N_")" N @N S $ZT="TRAP^cAN000" ; S ClassName="%Library.DynamicQuery",QueryName="SQL" ; S rs=##class(%Library.ResultSet).%New(ClassName_":"_QueryName) I 'rs s OK="0\Could not create an instance for the query" G FRZ ; I $L($G(ref)) k @ref ; s OK=rs.Prepare(query) I 'OK s OK="0\Could not prepare query : "_OK G FRY ; S OK=rs.Execute() I 'OK s OK="0\Could not excute query : "_OK G FRY ; S columns=rs.GetColumnCount() I '$G(head) G FRA ; header tonen W:$g(scr) ! S res="",tel=0 F i=1:1:columns S a=rs.GetColumnHeader(i) W:$g(scr) a,$C(9) I $l($g(ref)) S res=res_$s($l(res):"\",1:"")_a I $L($g(ref)) s @ref@(tel)=res ; details tonen FRA F tel=0:1 Q:rs.Next()=0 D . W:$g(scr) ! . S res="" F i=1:1:columns S a=rs.GetData(i) W:$g(scr) a,$C(9) I $l($g(ref)) S res=res_$s($l(res):"\",1:"")_a . I $l($g(ref)) S @ref@(tel)=res W:$g(scr) ! ; S OK=1_"\"_tel ; FRY S rs=rs.%Close() I rs'=1 S OK="0\Could not close the instance" ; ; FRZ Q OK ; ZZ ; 15.12.05 - 12 u 16 * V8.05