Custom Query that Returns a RANDOM number of columns
Hi!
I was trying to create a query that can be exposed as a stored procedure (function actually) that would return a resultset with a random number of columns.
Unfortunately, it seems that unless I specify the ROWSPEC annotation on the Query method, I won't get any columns exposed. I was hoping to implement QueryNameGetInfo method and specify the names and number of columns I would be returning dynamically. But it seems that GetInfo information is simply ignored.
Here is my code:
Class Test.Test { ClassMethod MyCustomQueryClose(ByRef qHandle As %Binary) As %Status { Quit $$$OK } ClassMethod MyCustomQueryExecute(ByRef qHandle As %Binary, ByVal pCubeName As %Library.String) As %Status { Quit $$$OK } ClassMethod MyCustomQueryFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status { Set Row=$ListBuild(1,"Amir",2,"Test") Set AtEnd=1 Quit $$$OK } ClassMethod MyCustomQueryGetInfo(ByRef colinfo As %List, ByRef parminfo As %List, ByRef idinfo As %List, ByRef qHandle As %Binary, extoption As %Integer = 0, ByRef extinfo As %List) as %Status { Set colinfo=$lb($lb("C1","10","C1"),$lb("C2","10","C2"),$lb("C3","10","C3"),$lb("C4","10","C4")) Set parminfo=$lb($lb("pCubeName","10")) Set idinfo=$lb(0,"") If extoption { Set extinfo=$lb("","") } Quit $$$OK } Query MyCustomQueryCube(ByVal pCubeName As %Library.String) As %Query [ SqlProc, SqlName = "GetFeaturesFromCube" ] { } }
I wonder if I am doing something wrong or if there is another way of doing this.
SQL is rather static and wants to be resolved at compile time.
What do you want to achieve?
You can have a classmethod that returns resultset(s). Check Sample.Person for example.
Hi!
I thought of that. But I really wanted to write a custom ObjectScript code instead of relying on a %SQL.Statement or %ResultSet. That is because the data I want to aggregate and return is not easily searchable with a single statement.
But I think I am going to be using %Dictionary.* to generate the code dynamically.
Kind regards,
AS
Amir,
If you want the results of your query to be usable by the outside world then you can easily do this by generating a custom query (subclass %SQL.CustomQuery), compile and execute it. I probably have some examples of doing this somewhere. %SQL.CustomQuery is a bit more convenient than defining a query in a class - it basically accomplishes the same thing. %SQL.CustomQuery will generate all of the relevant metadata from your property definitions and you do not have to be concerned with ROWSPEC, etc. It is fully compatible with SQL and can even be used as a TVF in other queries.
-Dan
Thank you! That helps a lot. The problem I was having is that I was implementing XXXGetInfo but not XXXGetODBCInfo().
Made a small demo with two options.