IRISLIB database
ResultSet Class Reference
Inheritance diagram for ResultSet:
Collaboration diagram for ResultSet:

Public Member Functions

_.Library.Status OnClose ()
 This callback method is invoked by the <METHOD>Close</METHOD> method to. More...
 
_.Library.Status Close ()
 Closes the current result set cursor.
 
_.Library.Integer ContainsId ()
 If the current query contains an object Id (based on the CONTAINSID parameter. More...
 
_.Library.Status Execute (args)
 Executes the current query. More...
 
_.Library.String Get (_.Library.String name)
 Returns the value of the column with the name name in the current row of the result set. More...
 
_.Library.Integer GetColumnCount ()
 Returns the number of columns in the result set.
 
_.Library.String GetColumnExtInfo (_.Library.Integer n)
 This method accepts the column number as an input parameter and will return a $list containing the class name and property. More...
 
_.Library.String GetColumnHeader (_.Library.Integer n)
 Returns the column header for column n in the result set.
 
_.Library.String GetColumnName (_.Library.Integer n)
 Returns the name of column n in the result set.
 
_.Library.Integer GetColumnType (_.Library.Integer n)
 Returns the type of column n in the result set where type is an integer associated with. More...
 
_.Library.String GetData (_.Library.Integer n)
 Returns the value of column n in the current row of the result set.
 
_.Library.String GetDataByName (_.Library.String name)
 Returns the value of the column with the name name in the current row of the result set. More...
 
_.Library.String GetExtent ()
 The name of the extent that this query will return Id values from (based on the EXTENT parameter. More...
 
_.Library.RegisteredObject GetObject ()
 If this query contains an object Id then this method opens an object with this Id. More...
 
_.Library.Integer GetParamCount ()
 Returns the number of input parameters for the current query.
 
_.Library.String GetParamName (_.Library.Integer n)
 Returns the name of input parameter n for the current query.
 
_.Library.String GetStatementType ()
 Returns the SQL statement type of the query if available. More...
 
_.Library.Integer Next (_.Library.Status sc)
 Advance the result set cursor to the next row. More...
 
_.Library.Status Prepare (args)
 Use this method with dynamic queries to provide the query to be. More...
 
_.Library.Integer QueryIsValid ()
 Returns true (1) if the ClassName and QueryName properties of this. More...
 
_.Library.Status SetIdInfo (_.Library.Integer idnumber, _.Library.String extent)
 Set the location of the ID in this query and the extent. More...
 
- Public Member Functions inherited from RegisteredObject
_.Library.Status OnAddToSaveSet (_.Library.Integer depth, _.Library.Integer insert, _.Library.Integer callcount)
 This callback method is invoked when the current object is added to the SaveSet,. More...
 
_.Library.Status OnConstructClone (_.Library.RegisteredObject object, _.Library.Boolean deep, _.Library.String cloned)
 This callback method is invoked by the <METHOD>ConstructClone</METHOD> method to. More...
 
_.Library.Status OnNew ()
 This callback method is invoked by the <METHOD>New</METHOD> method to. More...
 
_.Library.Status OnValidateObject ()
 This callback method is invoked by the <METHOD>ValidateObject</METHOD> method to. More...
 

Static Public Member Functions

 Test (_.Library.String ClassName, _.Library.String QueryName, args)
 This method is deprecated; use RunQuery.
 
- Static Public Member Functions inherited from AbstractResultSet
 RunQuery (_.Library.String ClassName, _.Library.String QueryName, args)
 This is a diagnostic function; it runs the specified query and prints the output to the console.
 

Public Attributes

 ClassName
 The name of the class containing the query to run. More...
 
 Data
 Used to store the data returned from the resultset by column name. More...
 
 QueryName
 The name of the query to run. More...
 
 RuntimeMode
 Use this property to set the SQL runtime mode for the query to be. More...
 
- Public Attributes inherited from AbstractResultSet
 Data
 Used to store the data returned from the resultset by column name. More...
 
 RuntimeMode
 Use this method to set the SQL runtime mode for the query to be. More...
 

Private Member Functions

_.Library.Status CloseCursor ()
 alias for new result set interface
 
 DispatchGetProperty (_.Library.String pProperty)
 Is used to get the value of an unknown property.
 
_.Library.Status Execute (args)
 alias for new result set interface
 
_.Library.String Get (_.Library.String name)
 Returns the value of the column with the name name in the current row of the result set. More...
 
_.Library.String GetData (_.Library.Integer colnbr)
 alias for new result set interface
 
_.Library.Integer Next (_.Library.Status sc)
 alias for new result set interface
 
_.Library.Status SendDelimitedRows (_.Library.Integer pMaxRows, _.Library.String pDelimiter, _.Library.Integer pReturnCount)
 Fetch and send a series of rows for continuous query client. More...
 
_.Library.Integer SendODBC ()
 Fetch and send a series of rows for the ODBC/JDBC server. More...
 

Static Private Member Functions

_.ResultSet.MetaData PrepareMetaData (_.Library.String pQueryId, _.SYSTEM.Error returnError, _.Library.RawString importPackages)
 PrepareMetaData is similar to Prepare except that no result set is instantiated. More...
 

Private Attributes

 __AtEnd
   More...
 
 __ColExtInfo
   More...
 
 __ColIndex
   More...
 
 __ColInfo
   More...
 
 __HasExtInfo
   More...
 
 __HasInfo
   More...
 
 __IdInfo
   More...
 
 __IsOpened
   More...
 
 __NextColumn
 This is the pointer to the next Column to be processed by <method>SendODBC</method>. More...
 
 __ParamInfo
   More...
 
 __QHandle
   More...
 
 __Row
   More...
 
 __StatementType
   More...
 

Additional Inherited Members

- Static Public Attributes inherited from RegisteredObject
 CAPTION = None
 Optional name used by the Form Wizard for a class when generating forms. More...
 
 JAVATYPE = None
 The Java type to be used when exported.
 
 PROPERTYVALIDATION = None
 This parameter controls the default validation behavior for the object. More...
 

Detailed Description

dynamic SQL is the preferred mechanism for preparing and executing dynamic SQL statements. Please refer to <class>SQL.Statement</class> for more information. Library.ResultSet continues to be used and supported.

The <class>ResultSet</class> class provides a way to use the results of class queries from within a ObjectScript application. It is similar in operation to the ResultSet objects provided with the ActiveX and Java bindings.

You can use a <class>ResultSet</class> object as follows:

Note you can bind a <class>ResultSet</class> object to a query by either a) setting the <property>ClassName</property> and <property>QueryName</property> properties or b) passing a string containing the class name and query name (separated by a :) to the <nobr>New</nobr> method:

; Display the results of the Person class' ByName query to the console. set rs=##class(ResultSet).New() set rs.ClassName="Sample.Person" set rs.QueryName="ByName" ; Alternatively, you can bind the result set object to a query ; set rs=##class(ResultSet).New("Sample.Person:ByName") set sc=rs.Execute("a") If $$$ISERR(sc) Do DisplayError^apiOBJ(sc) Quit while rs.Next() { do rs.Print() }

Dynamic SQL: You can use the <class>ResultSet</class> class to execute dynamic SQL queries using the system-provided <nobr>DynamicQuery:SQL</nobr> query. In this case, use the <method>Prepare</method> method to supply the text of the query. For example:

Set result=##class(ResultSet).New("%DynamicQuery:SQL")

Set sc=result.Prepare("SELECT %ID, Name, Salary FROM Sample.Employee WHERE Salary > ?") If $$$ISERR(sc) Do DisplayError^apiOBJ(sc) Quit Set sc=result.Execute(10000) If $$$ISERR(sc) Do DisplayError^apiOBJ(sc) Quit While result.Next(.sc) { If $$$ISERR(sc) Quit Write result.Data("Name"),result.Data("Salary"),! } If $$$ISERR(sc) Do DisplayError^apiOBJ(sc) Quit

Dynamic SQL queries are cached in the same query cache as used by InterSystems IRIS ODBC and JDBC. This means that repeated calls to the same dynamic SQL query do not incur any additional query preparation and optimization overhead. You can view and manage this cache using the SQL Manager.

Member Function Documentation

◆ Get() [1/2]

_.Library.String Get ( _.Library.String  colname)
private

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.

Reimplemented from AbstractResultSet.

◆ OnClose()

_.Library.Status OnClose ( )

This callback method is invoked by the <METHOD>Close</METHOD> method to.

provide notification that the current object is being closed.

The return value of this method is ignored.

Reimplemented from IResultSet.

Reimplemented in ScrollableResultSet.

◆ PrepareMetaData()

_.ResultSet.MetaData PrepareMetaData ( _.Library.String  pQueryId,
_.SYSTEM.Error  returnError,
_.Library.RawString  importPackages 
)
staticprivate

PrepareMetaData is similar to Prepare except that no result set is instantiated.

This

method returns a ResultSet.MetaData object. Be aware that the implementation of this method might cause the result set to be instantiated but that is up to the result set class itself and no result set is actually returned by this method - only metadata.

queryId This can be the concrete subclass of IResultSet that implements the desired query. For dynamic cached results this value is generally the query text that can be parsed, a hashed value computed and the cached result implementation class looked up in the query cache index.

<queryId> can also be a <className><colon><queryName> or <className><colon><methodName>. If it is a <queryName> then
the result set returned is an instance of %Library.ResultSet that is bound to that query. If it is the name of a method
Then that method is called, passing %args... to the method, and the first result set found in the context object (%sqlcontext)
is returned.

returnError If an error occurs this is returned by reference and is a SYSTEM.Error object with properties set to describe information about the error. returnError.Status contains the Status value. importPackages This is a comma delimited list of packages to import. This is only relevant if the result set implementation is generated and the query source might include unqualified names. The import packages list is used to resolve package/schema names for unqualified names.

Reimplemented from IResultSet.

◆ SendDelimitedRows()

_.Library.Status SendDelimitedRows ( _.Library.Integer  pMaxRows,
_.Library.String  pDelimiter,
_.Library.Integer  pReturnCount 
)
private

Fetch and send a series of rows for continuous query client.

For internal use only.

Reimplemented from IResultSet.

◆ SendODBC()

_.Library.Integer SendODBC ( )
private

Fetch and send a series of rows for the ODBC/JDBC server.

For internal use only.

◆ ContainsId()

_.Library.Integer ContainsId ( )

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.

Reimplemented from AbstractResultSet.

◆ Execute()

_.Library.Status Execute (   args)

Executes the current query.

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


This method sets the <property>SQLCODE</property> property if an error is reported. The value of <property>SQLCODE</property> is computed from the status value and is not set to the value of the public SQLCODE variable. The <property>Message</property>, <property>ROWCOUNT</property> and <property>ROWID</property> properties are set to the values of the SQL public variables msg, ROWCOUNT and ROWID. If those public variables were not set by the query's Execute method and those variables were defined prior to calling Execute then the properties will contain the prior values of those variables. It is the caller's responsibility to initialize and manage these public variables.

Reimplemented from AbstractResultSet.

◆ Get() [2/2]

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.
Using the <property>Data</property> multidimensional property to access the fields is faster than using this method call.

Reimplemented from AbstractResultSet.

◆ GetColumnExtInfo()

_.Library.String GetColumnExtInfo ( _.Library.Integer  n)

This method accepts the column number as an input parameter and will return a $list containing the class name and property.

name of the property corresponding to the column in the query. If the column is not based on a property then the returned information will be an empty $list.

◆ GetColumnType()

_.Library.Integer GetColumnType ( _.Library.Integer  n)

Returns the type of column n in the result set where type is an integer associated with.

the client datatype. If the type cannot be determined, 0 (zero) is returned.

1BINARY
2DATE
3DOUBLE
4HANDLE
5INTEGER
6LIST
7LONGVARCHAR
8TIME
9TIMESTAMP
10VARCHAR
11STATUS
12BINARYSTREAM
13CHARACTERSTREAM
14NUMERIC
15CURRENCY
16BOOLEAN
17OID
18BIGINT
19FDATE
20FTIMESTAMP

◆ GetDataByName()

_.Library.String GetDataByName ( _.Library.String  name)

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 <method>Get</method> method.

Reimplemented from AbstractResultSet.

◆ GetExtent()

_.Library.String GetExtent ( )

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.

Reimplemented from AbstractResultSet.

◆ GetObject()

If this query contains an object Id then this method opens an object with this Id.

and returns the object reference. Otherwise it returns a null object reference.

Reimplemented from AbstractResultSet.

Reimplemented in DataSet, and ScrollableResultSet.

◆ GetStatementType()

_.Library.String GetStatementType ( )

Returns the SQL statement type of the query if available.

Statement type numbers are defined as:

1SELECT
2INSERT (also 'INSERT OR UPDATE')
3UPDATE
4DELETE
5COMMIT
6ROLLBACK
7GRANT
8REVOKE
9CREATE TABLE
10ALTER TABLE
11DROP TABLE
12CREATE VIEW
13ALTER VIEW
14DROP VIEW
15CREATE INDEX
16ALTER INDEX (Not supported)
17DROP INDEX
18CREATE ROLE
19DROP ROLE
20SET TRANSACTION
21START TRANSACTION
22INTRANSACTION
23BEGTRANS (Alias for START TRANSACTION)
24INTRANS (Alias for INTRANSACTION)
25GET (Not supported)
26SET OPTION
27STATISTICS (UPDATE STATISTICS, not supported))
28CHECKPRIV
29CREATE USER
30ALTER USER
31DROP USER
32CHECKPRIV (SQL Admin Privilege)
33GRANT (SQL Admin Privilege)
34REVOKE (SQL Admin Privilege)
35CREATE FUNCTION
36CREATE METHOD
37CREATE PROCEDURE
38CREATE QUERY
39DROP FUNCTION
40DROP METHOD
41DROP PROCEDURE
42DROP QUERY
43CREATE TRIGGER
44DROP TRIGGER
45CALL
46SAVEPOINT
47LOCK TABLE
48UNLOCK TABLE
49CREATE DATABASE
50DROP DATABASE
51USE DATABASE
""Anything not list above

◆ Next()

Advance the result set cursor to the next row.

Returns 0 if the cursor is at the end of the

result set.

Reimplemented from AbstractResultSet.

Reimplemented in ScrollableResultSet.

◆ Prepare()

_.Library.Status Prepare (   args)

Use this method with dynamic queries to provide the query to be.

executed. In the case of the <nobr>DynamicQuery:SQL</nobr> 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 <method>Execute</method> 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"),! }

Reimplemented from AbstractResultSet.

◆ QueryIsValid()

_.Library.Integer QueryIsValid ( )

Returns true (1) if the ClassName and QueryName properties of this.

<nobr>ResultSet</nobr> object refer to a valid class query. Otherwise it returns false (0).

Reimplemented from AbstractResultSet.

◆ SetIdInfo()

_.Library.Status SetIdInfo ( _.Library.Integer  idnumber,
_.Library.String  extent 
)

Set the location of the ID in this query and the extent.

The idnumber is

the column number of the ID and the extent is the class name the id is from. Note, you must call this after the Execute method is called or the data will be overwritten.

Member Data Documentation

◆ __AtEnd

__AtEnd
private

 

 

◆ ClassName

ClassName

The name of the class containing the query to run.

 

◆ __ColExtInfo

__ColExtInfo
private

 

 

◆ __ColIndex

__ColIndex
private

 

 

◆ __ColInfo

__ColInfo
private

 

 

◆ Data

Data

Used to store the data returned from the resultset by column name.

This can

be accessed directly for better performance than the <method>Get</method> and <method>GetDataByName</method> methods. For example:

; This slower code

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 because 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 <method>GetData</method> and give the position of the column you want.  

◆ __HasExtInfo

__HasExtInfo
private

 

 

◆ __HasInfo

__HasInfo
private

 

 

◆ __IdInfo

__IdInfo
private

 

 

◆ __IsOpened

__IsOpened
private

 

 

◆ __NextColumn

__NextColumn
private

This is the pointer to the next Column to be processed by <method>SendODBC</method>.

When <method>SendODBC</method> is next called, this will be the first column to be sent. This value is zero if no data is unprocessed, non zero if there is something to process It is set to 1 on every Next() call that returns a valid row.  

◆ __ParamInfo

__ParamInfo
private

 

 

◆ __QHandle

__QHandle
private

 

 

◆ QueryName

QueryName

The name of the query to run.

 

◆ __Row

__Row
private

 

 

◆ RuntimeMode

RuntimeMode

Use this property 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.

 

◆ __StatementType

__StatementType
private