Written by

~~ retired but not tired ~~
MOD
Article Robert Cemper · Mar 2, 2023 5m read

Tutorial - Working with %Query #3

My previous article introduced you to the COS based Custom Class Query.
There were some features missing like more lines of the stream displayed
and numbered.

The basic idea is the same.
A new input parameter chunks is introduced that sets a limit of displayed
pieces of our stream.

/// pack all params into qHandle/// called only once at startClassMethod Q2Execute(
	ByRef qHandle As%Binary,
	idfrom As%Integer = 1,
	idto As%Integer = 0,
	maxtxt As%Integer = 25,
	chunks As%Integer = 1) As%Status
{
  set qHandle={}
  set qHandle.id=0set qHandle.idfrom=idfrom
  set qHandle.idto=idto
  set qHandle.obj=0set qHandle.stream=0set qHandle.maxtxt=maxtxt
  set qHandle.chunks=chunks
  set qHandle.chcnt=1Quit$$$OK
}
  • I now have a limit and a counter of displayed chunks default is 1 chunk
  • the Stream Object is kept open in qHandle to avoid reload
  • once the stream is empty I jump to the next available object.

and it looks like that:
 

[SQL]USER>>call rcc.Q2(1,,,3)
11.     call rcc.Q2(1,,,3)

Dumping result #1
ID      City    Name    Age     chunk   Stream
1       Bensonh Kovalev 161       Building shareholder valu
_       _       _       _       2       e by delivering secure di
_       _       _       _       3       stributed devices and med
2       Queensb Yeats   151       Spearheading the next gen
_       _       _       _       2       eration of high-performan
_       _       _       _       3       ce genetic virtualized in
4       Newton  Evans   6115       Hialeah Zemaiti 471       Resellers of premise-base
_       _       _       _       2d secure XML services for
_       _       _       _       3        social networks.||TwoToL
6       Elmhurs Jenkins 291       Enabling individuals and
_       _       _       _       2       businesses to manage ente
_       _       _       _       3       rprise models for social
7       Islip   Drabek  611       Building shareholder valu
_       _       _       _       2       e by delivering open crow
_       _       _       _       3d-sourced voice-enabled c
8       Islip   Kovalev 881       Experts in standards-base
_       _       _       _       2d distributed voice-enabl
_       _       _       _       3       ed services for social ne
 
19 Rows(s) Affected
statement prepare time(s)/globals/lines/disk: 0.0069s/2022/14949/0ms
          execute time(s)/globals/lines/disk: 0.0025s/48/5520/0ms
                          cached query class: %sqlcq.USER.cls82
---------------------------------------------------------------------------

for shorter streams it terminates when stream ends

[SQL]USER>>call rcc.Q2(,4,70,20)
22.     call rcc.Q2(,4,70,20)
 
Dumping result #1
ID      City    Name    Age     chunk   Stream
1       Bensonh Kovalev 161       Building shareholder value by delivering secure distributed devices an
_       _       _       _       2d media for the Health Care community.||Scope ||An AmAn LoIcA On||Iso|
_       _       _       _       3       |PlasmA||Atic CoLoIO||IcOpIon An Lo||Re||Ies Tw||Lo Dyna I||Atic To Ly
_       _       _       _       4       ||Ecto O||AticL||Ism IAn Look||Plasm ||A||A Cop||Two IRe ||Two ||I||Dy
_       _       _       _       5       na Much LoN||Ion AmQuoAn Ec||OpOc||IcTwoCycl||A ComRe||I||GeoPedeLo ||
_       _       _       _       6       Pus EndoPyro||IesIsoIsmCom Te||A||Pyro||I On An I Tr||Syn AIcA||Gyro P
_       _       _       _       7       ho||AmCo UniTe||AScope ComQuo IH||Two A Ect||Graph ||A ||Pyro Heli AnR
_       _       _       _       8       eAn||Muc||Range IcTri||IonIsoIonAnC||A Wave Lo I||PusAt||To||Able ||Lo
_       _       _       _       9       Ati||A||Quo||Ly LyIc||***Done***
2       Queensb Yeats   151       Spearheading the next generation of high-performance genetic virtualiz
_       _       _       _       2       ed instruments for the Fortune 500.||LoI||IesMorphSy||Re Uni ||CoQuoEc
_       _       _       _       3       to||Tech IesOn ||Invent Vi||To LyIonGeoIc||Able||Ion Ect||Co I Ic Quo
_       _       _       _       4       U||AOn Much Ly To||Iso Much G||Am||LoIsmGraph Pus ||ReOp ViaComLo||OpI
_       _       _       _       5        TheticOn R||Ly OpCopter Mil||Quo Am Te||T||Plasm Type||On IsoIOpIcOp
_       _       _       _       6       P||I Dyna Tech Q||IGeo Dyna ||An AmLyCo Ion||Ic AnIsm Phot||IesAmI Am
_       _       _       _       7       OpA||KiloAnLo Am Co||Op ATr||TheticGraph||P||IcIc IOnTwoT||Ped||On On
_       _       _       _       8       QuoAnGrap||I||Copter LyQuo||ALookIcMuch Dyn||Abl||Re CoIcMuchCo A||ReO
_       _       _       _       9       nMuchAnToGr||TheticToTec||Ism Ies A||An AIAbleCo ||Q||LoI||Pus Ly ATri
_       _       _       _       10      On G||SoundU||To Heli Com||AOn||Ly Re||ComInventLoR||***Done***
4       Newton  Evans   61120 Rows(s) Affected
statement prepare time(s)/globals/lines/disk: 0.0065s/2020/15410/0ms
          execute time(s)/globals/lines/disk: 0.0021s/33/5048/0ms
                          cached query class: %sqlcq.USER.cls84
---------------------------------------------------------------------------
  • the next step is to honor the separators and display segments
  • and also allow groups of segments
  • As the basic functionality is there it's more a matter of chopping the streams 

Follow me on to the next chapter for the extension of this example that
will show and control more result lines.

Just a reminder:
All test data are generated using the System method %Populate
So your output will be different. I suggest you run our tests also with other parameters
than the shown examples to get the full power of this tool.

The full code example is again available on GitHub  

The Video is available now. See section Custom Class Query 

For immediate access, you can use Demo Server WebTerminal  
and the related system Management Portal on Demo Server SMP

I hope you liked it so far and I can count on your votes.

Comments