Skip to main content

HS.Util.TransientTable

class HS.Util.TransientTable extends %SQL.IResultSet

This class is a direct copy of HSTA.Core.TransientTable, and made available for Health Connect. This class provides a ResultSet-style iterator object that also allows to programmatically set column names, set data into new result rows, and to iterate through the result set. It also provides the ability to hold extremely large result sets due to its use of %SQL.IResultSet, which holds its data in a process-private global. The following methods are added in this extending of %SQL.IResultSet:
%AddColumn(columnName, dataType) - this adds a new column definition. The dataType is in SQL format - VARCHAR(200) for example;
%Set() - set a column by column name
%SetData() - set a column by column number
%NewRow() - advance the iterator to beyond the last row, initialize the %Data array
%SaveRow() - save the current row, replacing the existing row, if any, entirely.

Method Inventory

Methods

method %AddColumn(colname As %String = "", dataType As %String = "", nullable As %Integer = 1, position As %Integer = "") as %Integer
method %AddColumnByMD(column As %SQL.StatementColumn = "") as %Integer
method %AddColumnByOid(oid As %List) as %Integer
method %AddColumns(ByRef colArray, nullable As %Integer = 1) as %Integer
Adding all columns at once is much more performant than a series of calls to %AddColumn This is due to calls to %GetMetadata() and refreshMetadata() being slow Inputs: colArray : array of column info to add in form colArray(idx) = "colname,colDataType" : colArray(1) = "Deleted,%String" : colArray(2) = "Key,%String" nullable : is the column able to be 'null' - defaults to 1
method %AddResultSet(rs As %IResultSet) as %Status
method %ColumnIndex(columnName As %String, Output dir As %Integer) as %Integer
method %ColumnValueToString(pValue As %String, pColumn As %Integer) as %String
method %Get(colname As %String = "") as %Library.String
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(colnbr As %Integer = 0) as %Library.String
Returns the value of column colnbr in the current row of the result set.
method %NewRow() as %Library.Integer
method %Next(ByRef sc As %Library.Status = $$$OK) as %Library.Integer
Advance the result set cursor to the next row. Returns 0 if the cursor is at the end of the result set. The global structure consists of a base $list with individual nodes for columns. The base $list() can contain zero or more column values. Additional column values are stored in the global subscripted by column number and equal to the column value.
method %Print(pDelimiter As %Library.String = " ", colAlign As %Library.Integer = 0, ByRef metadata As %Library.ArrayOfObjects) as %Status
%Print()

Write the current row to the current device. An optional column delimiter can be specified. No formatting is applied other than writing pDelimiter between column values. This can be useful for exporting result set data to tab delimited files.

For example:

   set sql = "select name,home_street,home_city,home_state,home_zip from sample.person"
   set rset = ##class(%ResultSet.SQL).%Prepare(.sql,.err,"")
   if '$Isobject(err) {
   	set file="c:\temp\names.asv"
   	open file:"WNS"
   	use file while rset.%Next() { do rset.%Print($char(9)) } 
   	close file
   }
   

Example data:

Cornell,Ezra M.340 Franklin CourtSarasotaNY12866
Huff,Stephen A.548 Washington BlvdBrownfield CenterMD53436
Sands,Jeep Q.7298 Washington DriveXavierWY23685
method %ROWCOUNTGet() as %Integer
%RowCount for a static result set is always the number of rows in the static set.
method %RegsiterToStringMethod(pColumn As %Integer, call As %String)
Registers a custom method to convert internal value to string for contents of the given column

The call argument should be in the format: "class:method"

classmethod %RestoreFrom(gbl As %String, offset As %String) as TransientTable
method %Save() as %Status
method %SaveRow() as %Status
method %SaveTo(gbl As %String, offset As %String = "") as %String
method %SendODBC() as %Library.Integer
Fetch and send a series of rows for the ODBC/JDBC server. For internal use only.
method %SendRows() as %Integer
method %Set(colname As %String = "", value As %Library.RawString = "") as %Integer
Set the column whose name is colname to value.
method %SetData(colnbr As %Integer = 0, value As %Library.RawString = "") as %Integer
method %SetIterator(pRowNumber As %Library.Integer = 0) as %Library.Integer
method %Sort(by...) as TransientTable
classmethod %nextNode(a As %String, ByRef idx, ByRef dir, Output row) as %Boolean
method refreshMetadata(rsmd As %SQL.StatementMetadata = "")
After adding a new column, it will be necessary to rebuild the xDBC metadata properties - only %Metadata is affected and then only the columns section and perhaps the extended metadata for objects. We don't support adding new parameters. Input: rsmd : can be passed in to avoid an extra call to %GetMetadata

Inherited Members

Inherited Properties

Inherited Methods

Subclasses

FeedbackOpens in a new tab