0

Here's a Query Method:

Query getSample() As %SQLQuery [ SqlProc ]
{
    SELECT * FROM TEST.xSample
}

The getSample Query will be called by a method in VB and it would be assigned to a DataTable typed object.

How can a ClassMethod that would return the same %SQLQuery that could be assigned to a DataTable typed object?

Diaton
  • 151
  • 7

2 Answers2

0

Why you want to use ClassMethod like Query ?

DAiMor
  • 3,185
  • 16
  • 24
0

I don't know that it would be easy to return this as a return value from a classmethod. SQL-based interfaces have the ability to process a resultset, including an understanding that the calling code needs to iterate over the results. If the number of results can get very large, this can be necessary!

As such, I think you need to think about how you want to handle the results. You could use %SQL.Statement to return a resultset of type %SQL.StatementResult, but you won't make your interface very clear as the resultset is dynamically generated and would still require the caller to do any interation over the results. That could look something like this:

ClassMethod GetSample() As %SQL.StatementResult
{
  // Note - this code uses %ExecDirect() as a shortcut.
  // For more control over the resultset, instantiate a %SQL.Statement instance, and then call %Prepare() and %Execute()
  Set tResultSet = ##class(%SQL.Statement).%ExecDirect(,"SELECT * FROM Test.xSample")
  Quit tResultSet
}

You could also return a list of objects, but that could make use of a lot of memory if your table is large, and your calling code would still need to iterate over the results and know what properties exist. You may want to explain what you actually need to do with your results to get better answers.

DdP
  • 438
  • 2
  • 6
  • Thanks for the insight. My initial idea is, have a bunch of result sets within the ClassMethod, process some records and then call another result set then return it. Would there be any other solution for this approach? Other than making a SQL transaction? – Diaton Nov 15 '13 at 00:11
  • A quick question.. Why does the ClassMethod returns an integer value, rather than the result set itself? 22@%sqlcq.SAMPLE.cls4 – Diaton Nov 15 '13 at 05:05
  • Inside Cache the return value is simply a reference to a resultset object, so calling your classmethod directly from SQL will return this reference. I don't think I understand what you were looking to do with the returned result set. – DdP Mar 31 '14 at 13:36