Question
· Feb 8, 2022

Viewing query string from %ResultSet

Hi guys, just a quick question on how get the sql statement that has been executed in a %ResultSet?

so basically after the execute command I would like to save the SQL statement generated in a eg, a global and check sql statement?

Set rset1 = ##class(%ResultSet).%New()
Set sc = rset1.Prepare("Select statment ")
Set:+sc sc = rset1.Execute(parm1,parm2)

Maybe something like s ^sql=rset1.Getstatment !?

Thanks

Product version: Caché 2014.1
Discussion (3)2
Log in or sign up to continue

If you are using Ensemble you can use EnsLib.SQL.Snapshot.

This helper class can persist ResutSet in global :

Set rset1 = ##class(%ResultSet).%New()
set sc = rset1.Prepare("Select * FROM Ens_Util.Log")
Set:+sc sc = rset1.Execute()

set snap = ##class(EnsLib.SQL.Snapshot).CreateFromResultSet(rset1)
set glb = snap.%GblRef

zw @glb

glb :

%Ensemble("12@EnsLib.SQL.Snapshot")=21
%Ensemble("12@EnsLib.SQL.Snapshot",1,1)=1
%Ensemble("12@EnsLib.SQL.Snapshot",1,2)=""
%Ensemble("12@EnsLib.SQL.Snapshot",1,3)=445
%Ensemble("12@EnsLib.SQL.Snapshot",1,4)=""
%Ensemble("12@EnsLib.SQL.Snapshot",1,5)=""
%Ensemble("12@EnsLib.SQL.Snapshot",1,6)="Ens.Director"
%Ensemble("12@EnsLib.SQL.Snapshot",1,7)="StartProduction"
%Ensemble("12@EnsLib.SQL.Snapshot",1,8)=""
%Ensemble("12@EnsLib.SQL.Snapshot",1,9)="Production 'Connector.Production' starting..."
%Ensemble("12@EnsLib.SQL.Snapshot",1,10)="2022-02-08 14:29:33.724"
%Ensemble("12@EnsLib.SQL.Snapshot",1,11)=""
%Ensemble("12@EnsLib.SQL.Snapshot",1,12)=4
%Ensemble("12@EnsLib.SQL.Snapshot",2,1)=2
%Ensemble("12@EnsLib.SQL.Snapshot",2,2)="Ens.Actor"
%Ensemble("12@EnsLib.SQL.Snapshot",2,3)=618
%Ensemble("12@EnsLib.SQL.Snapshot",2,4)=""
%Ensemble("12@EnsLib.SQL.Snapshot",2,5)=""
%Ensemble("12@EnsLib.SQL.Snapshot",2,6)="Ens.Job"
%Ensemble("12@EnsLib.SQL.Snapshot",2,7)="Start"
%Ensemble("12@EnsLib.SQL.Snapshot",2,8)=""
%Ensemble("12@EnsLib.SQL.Snapshot",2,9)="ConfigItem 'Ens.Actor' started in job 618"
%Ensemble("12@EnsLib.SQL.Snapshot",2,10)="2022-02-08 14:29:33.978"
%Ensemble("12@EnsLib.SQL.Snapshot",2,11)=""
%Ensemble("12@EnsLib.SQL.Snapshot",2,12)=4
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs")=12
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","configname")=2
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","id")=1
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","job")=3
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","messageid")=4
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","sessionid")=5
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","sourceclass")=6
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","sourcemethod")=7
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","stack")=8
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","text")=9
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","timelogged")=10
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","tracecat")=11
%Ensemble("12@EnsLib.SQL.Snapshot","ColIDs","type")=12
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames")=12
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",1)="ID"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",2)="ConfigName"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",3)="Job"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",4)="MessageId"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",5)="SessionId"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",6)="SourceClass"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",7)="SourceMethod"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",8)="Stack"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",9)="Text"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",10)="TimeLogged"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",11)="TraceCat"
%Ensemble("12@EnsLib.SQL.Snapshot","ColNames",12)="Type"
%Ensemble("12@EnsLib.SQL.Snapshot","ColSizes")=12
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes")=12
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",1)="BIGINT"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",2)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",3)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",4)="INTEGER"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",5)="INTEGER"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",6)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",7)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",8)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",9)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",10)="TIMESTAMP"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",11)="VARCHAR"
%Ensemble("12@EnsLib.SQL.Snapshot","ColTypes",12)="INTEGER"

If you are not using Ensemble, I guess you will have to build this kind of helper class by your self.