How to do a SQL query on a multilevel global and display each level in the same table ?
Hello,
I have a global whose structure is multi-level and I am trying through a class and a SQL query to display a table which includes all the values and levels.
^AFO("Site","Ville")="66722,3743"
^AFO("Site","Ville","111BB","OBT")=",MMM,XXX,"
^AFO("Site","Ville","111OW","OBT")=",XXX,MMM,"
^AFO("Site","Ville","AANVRBIBS","zzz") = "1^^1"
^AFO("Site","Ville","AANVRBIBS","zzz","*","dut") = "*afhalen waar gevonden"
^AFO("Site","Ville","AANVRBIBS","zzz","*","eng") = "*Pickup where found"
^AFO("Site","Ville","AANVRBIBS","zzz","*","fre") = "*Lieu où trouvé"
and here is the table that I would like to have :
|
1 |
Ville |
|
|
|
|
66722,3743 |
|
2 |
Ville |
111BB |
OBT |
|
|
,MMM,XXX |
|
3 |
Ville |
111OW |
OBT |
|
|
,XXX,MMM |
|
4 |
Ville |
AANVRBIBS |
zzz |
|
|
1^^1 |
|
5 |
Ville |
AANVRBIBS |
zzz |
* |
dut |
*afhalen waar gevonden |
|
6 |
Ville |
AANVRBIBS |
zzz |
* |
eng |
*Pickup where found |
|
7 |
Ville |
AANVRBIBS |
zzz |
* |
fre |
*Lieu où trouvé |
Does anyone have a solution?
Thanks in advance
Comments
The answer has been given in French here by @Lorenzo Scalese
You can create a custom class query like this:
Class dc.Frank
{
Query QueryAFO() As %Query(ROWSPEC = "key1:%String,key2:%String,key3:%String,key4:%String,key5:%String,key6:%String,datavalue:%String") [ SqlProc ]
{
}
ClassMethod QueryAFOExecute(ByRef qHandle As %Binary) As %Status
{
Set qHandle("node") = $Name(^AFO)
Quit $$$OK
}
ClassMethod QueryAFOFetch(
ByRef qHandle As %Binary,
ByRef Row As %List,
ByRef AtEnd As %Boolean) As %Status [ PlaceAfter = QueryAFOExecute ]
{
Set sc = $$$OK
Set qHandle("node") = $Query(@qHandle("node"), 1, data)
If qHandle("node") = "" Set Row = "", AtEnd = $$$YES Quit $$$OK
; feeds the key x fields based on the subscripts of the global
For i=1:1:$QLength(qHandle("node")) Set $List(Row, i) = $QSubscript(qHandle("node"), i)
If i < 6 { ; if we do not have 6 subscripts, we feed the rest with an empty string
For j = i+1:1:6 Set $List(Row, j) = ""
}
Set $List(Row, 7) = data, AtEnd = $$$NO
Quit sc
}
ClassMethod QueryAFOClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = QueryAFOExecute ]
{
Kill qHandle Quit $$$OK
}
/// just for some test data
ClassMethod set()
{
s ^AFO("Site","Ville")="66722,3743"
s ^AFO("Site","Ville","111BB","OBT")=",MMM,XXX,"
s ^AFO("Site","Ville","111OW","OBT")=",XXX,MMM,"
s ^AFO("Site","Ville","AANVRBIBS","zzz") = "1^^1"
s ^AFO("Site","Ville","AANVRBIBS","zzz","*","dut") = "*afhalen waar gevonden"
s ^AFO("Site","Ville","AANVRBIBS","zzz","*","eng") = "*Pickup where found"
s ^AFO("Site","Ville","AANVRBIBS","zzz","*","fre") = "*Lieu où trouvé"
}
}
You can then easily exploit it with the following query:
select *
from dc.Frank_QueryAFO()
In terminal mode, you can also simply use this line to display the results:
Do ##class(dc.Frank).QueryAFOFunc().%Display()For my part, I carried out the test on IRIS 2023.2, there should be no incompatibility, but if you notice a problem do not hesitate to respond with the error message.
did you try Global-dump-to-SQL ?
it's not so fresh (from 2020) but just works for any Global
description is here Show Global by SQL SELECT