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.
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.
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:
method %Execute(args...) as %Library.Status [ Language = objectscript ]
alias for new result set interface
method %Get(name As %String) as %String [ Language = objectscript ]
Inherited description: 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.
method %GetData(n As %Integer) as %String [ Language = objectscript ]
Inherited description: Returns the value of column colnbr in the current row of the result set.
method %Next(ByRef sc As %Status) as %Integer [ Language = objectscript ]
Inherited description: Advance the result set cursor to the next row. Returns 0 if the cursor is at the end of the
result set.
method Close() as %Status [ Language = objectscript ]
Closes the current result set cursor.
abstract method ContainsId() as %Integer [ Language = objectscript ]
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.
method Execute(args...) as %Status [ Language = objectscript ]
Executes the current query.
The arguments p1... supply the value of any parameters the
query may have.
abstract method Get(name As %String) as %String [ Language = objectscript ]
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.
abstract method GetColumnCount() as %Integer [ Language = objectscript ]
Returns the number of columns in the result set.
abstract method GetColumnHeader(n As %Integer) as %String [ Language = objectscript ]
Returns the column header for column n in the result set.
abstract method GetColumnName(n As %Integer) as %String [ Language = objectscript ]
Returns the name of column n in the result set.
abstract method GetData(n As %Integer) as %String [ Language = objectscript ]
Returns the value of column n in the current row of the result set.
abstract method GetDataByName(name As %String) as %String [ Language = objectscript ]
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.
abstract method GetExtent() as %String [ Language = objectscript ]
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.
abstract method GetObject() as %RegisteredObject [ Language = objectscript ]
If this query returns the object Id then return the oref you get from
opening an object with this id.
abstract method GetParamCount() as %Integer [ Language = objectscript ]
Returns the number of input parameters for the current query.
abstract method GetParamName(n As %Integer) as %String [ Language = objectscript ]
Returns the name of input parameter n for the current query.
method Next(ByRef sc As %Status) as %Integer [ Language = objectscript ]
Advance the result set cursor to the next row. Returns 0 if the cursor is at the end of the
result set.
method Prepare(args...) as %Status [ Language = objectscript ]
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"),!
}
abstract method QueryIsValid() as %Integer [ Language = objectscript ]
Returns true (1) if the ClassName and QueryName properties of this
%ResultSet object refer to a valid class query.
Otherwise it returns false (0).
classmethod RunQuery(ClassName As %String, QueryName As %String, args...) [ Language = objectscript ]
This is a diagnostic function; it runs the specified query and prints the output to the console.