Skip to main content

%Library.AbstractResultSet

Class %Library.AbstractResultSet Extends %IResultSet [ Abstract, System = 2 ]

Abstract version of the resultset which specific implementations of result sets inherit from.

A result set is a type of result returned by executing either a SELECT statement or a CALL statement. Please refer to %SQL.Statement and %SQL.StatementResult for more information on how to prepare dynamic SQL statements and how to process the results the of executing them.

Properties

RuntimeMode

Property RuntimeMode As %String;

Use this method to set the SQL runtime mode for the query to be executed. Setting the runtime mode for this ResultSet does not permanently change the $zu(115,5) value. Possible values mode are:

  • 0 for LOGICAL mode.
  • 1 for ODBC mode.
  • 2 for DISPLAY mode.
  • "" to use the process wide $zu(115,5) value.

Data

Property Data As %String [ MultiDimensional ];

Used to store the data returned from the resultset by column name. This can be accessed directly for more performance than the Get and GetDataByName as it avoids a method call. For example code that said: While result.Next() { Write result.Get("Name"),result.Get("Salary"),! } ; Becomes this faster code While result.Next() { Write $get(result.Data("Name")),$get(result.Data("Salary")),! } Note that as this 'Data' property is multidimensional if there is no such column name as 'Salary' you will get an UNDEFINED error without the $get around it. If there are two columns with the same name in the result set then the second one will be the one referenced by the 'Data' property. If you need to refer to both of them use the GetData and give the position of the column you want.

Methods

Prepare

Method Prepare(args...) As %Status

Use this method with dynamic queries to provide the query to be executed. In the case of the %DynamicQuery:SQL query, p1 is a string containing an SQL query. The query may contain parameters represented by ? characters within the query. The values of any parameters are supplied via the Execute method. For example: Set result=##class(%ResultSet).%New("%DynamicQuery:SQL") Do result.Prepare("SELECT Name,City FROM Person WHERE Name %STARTSWITH ? AND City = ?") Do result.Execute("A","Boston") While result.Next() { Write result.Data("Name"),result.Data("City"),! }

Execute

Method Execute(args...) As %Status

Executes the current query.

The arguments p1... supply the value of any parameters the query may have.

%Execute

Method %Execute(args...) As %Library.Status [ CodeMode = call ]

alias for new result set interface

Next

Method Next(ByRef sc As %Status) As %Integer

Advance the result set cursor to the next row. Returns 0 if the cursor is at the end of the result set.

%Next

Method %Next(ByRef sc As %Status) As %Integer [ CodeMode = call ]

GetData

Method GetData(n As %Integer) As %String [ Abstract ]

Returns the value of column n in the current row of the result set.

%GetData

Method %GetData(n As %Integer) As %String [ CodeMode = call ]

Get

Method Get(name As %String) As %String [ Abstract ]

Returns the value of the column with the name name in the current row of the result set.

If name is not a valid column name, this method returns an empty string. Look at updating the code to use the Data multidimensional property to access the fields faster than using this method call.

%Get

Method %Get(name As %String) As %String [ CodeMode = call ]

GetDataByName

Method GetDataByName(name As %String) As %String [ Abstract ]

Returns the value of the column with the name name in the current row of the result set.

If name is not a valid column name, this method returns an empty string.

Note: this method has been superceded by the equivalent Get method.

GetObject

Method GetObject() As %RegisteredObject [ Abstract ]

If this query returns the object Id then return the oref you get from opening an object with this id.

Close

Method Close() As %Status

Closes the current result set cursor.

GetColumnCount

Method GetColumnCount() As %Integer [ Abstract ]

Returns the number of columns in the result set.

GetColumnName

Method GetColumnName(n As %Integer) As %String [ Abstract ]

Returns the name of column n in the result set.

GetColumnHeader

Method GetColumnHeader(n As %Integer) As %String [ Abstract ]

Returns the column header for column n in the result set.

GetParamCount

Method GetParamCount() As %Integer [ Abstract, CodeMode = expression ]

Returns the number of input parameters for the current query.

GetParamName

Method GetParamName(n As %Integer) As %String [ Abstract, CodeMode = expression, ProcedureBlock = 1 ]

Returns the name of input parameter n for the current query.

QueryIsValid

Method QueryIsValid() As %Integer [ Abstract, CodeMode = expression ]

Returns true (1) if the ClassName and QueryName properties of this %ResultSet object refer to a valid class query. Otherwise it returns false (0).

ContainsId

Method ContainsId() As %Integer [ Abstract, CodeMode = expression ]

If the current query contains an object Id (based on the CONTAINSID parameter being set), return the column position of the object Id. Otherwise return 0.

GetExtent

Method GetExtent() As %String [ Abstract, CodeMode = expression ]

The name of the extent that this query will return Id values from (based on the EXTENT parameter being set). Only returns a value if the query contains Id values.

RunQuery

ClassMethod RunQuery(ClassName As %String, QueryName As %String, args...)

This is a diagnostic function; it runs the specified query and prints the output to the console.