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

Private Member Functions

 Display (_.Library.String pDelimiter)
 Displays the contents of this object on the current device.
 
 DisplayFormatted (_.Library.String pFormat, _.Library.String pFileName, _.SQL.Manager.Messages pMessages, _.Library.String pFilesUsed, _.Library.String pTranslateTable, _.Library.String pDelimiter)
 Displays the contents of the result object. More...
 
_.Library.String Get (_.Library.String colname)
 Returns the value of the column with the name colname in the current row of the result set. More...
 
_.Library.String GetData (_.Library.Integer colnbr)
 Returns the value of column colnbr in the current row of the result set.
 
_.SQL.StatementMetadata GetMetadata ()
 Returns the result set metadata as a SQL.StatementMetadata instance.
 
_.Library.Integer GetRow (_.Library.List Row, _.Library.Status sc)
 Advances to the next row in the result referenced by <property>ProcCursor</property>. More...
 
_.Library.Integer GetRows (_.Library.Integer Cnt, _.Library.List Rows, _.Library.Status sc)
 Advances the next <parameter>Cnt</parameter> rows in the result referenced by <property>ProcCursor</property>. More...
 
_.Library.Integer MoreResults ()
 Invokes <method>NextResult</method> to return the next result object from a statement result object (aka 'context object') and. More...
 
_.Library.Integer Next (_.Library.Status sc)
 Advances to the next row in the result referenced by <property>ProcCursor</property>. More...
 
_.Library.RawString NextOutputValue (_.Library.Integer pPosition)
 Returns the output value from the position following pPosition. More...
 
_.Library.RegisteredObject NextResult ()
 Returns the next result object from a statement descriptor (aka 'context object'). More...
 
_.Library.Status NormalizeObject ()
 Normalizes all of an object's property values by invoking the data type Normalize methods. More...
 
_.Library.Status Print (_.Library.String pDelimiter)
 This is an abstract method. More...
 

Additional Inherited Members

- 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 OnClose ()
 This callback method is invoked by the <METHOD>Close</METHOD> method to. 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 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

For details on using this class, see Using Dynamic SQL.

<class>SQL.StatementResult</class> is the result descriptor class, returned by the Execute() and ExecDirect() methods of <class>SQL.Statement</class>. Use this class to examine the results of the query.

The content of a statement result object varies depending on the statement type and whether or not the statement was successfully executed. The interface to the result object is the same for all statement types but the content of the result object varies.

When retrieving results, first check for successful execution by examining <property>SQLCODE</property>. If SQLCODE is greater than or equal to zero, then the statement was successfully executed. Otherwise, the value of SQLCODE contains the error code and the <property>Message</property> property might contain more information about the error. See <property>SQLCODE</property> for additional comments.

Many statements affect some number of rows. The number of rows affected by the statement execution is contained in the <property>ROWCOUNT</property> property. For a SELECT statement, if the cursor is positioned after the last row, the value of <property>ROWCOUNT</property> indicates the number of rows contained in the result set. At any other time, <property>ROWCOUNT</property> contains the number of rows retrieved thus far. <property>ROWID</property> is set to the RowID of the last record modified by the most recent INSERT, UPDATE, INSERT OR UPDATE, DELETE, or TRUNCATE TABLE operation. After an INSERT statement, the <property>ROWID</property> property contains the system-assigned value of the RowID (Object ID) assigned to the new record.

A successfully executed SELECT statement returns a single result set. The number of columns in the result set is contained in <property>ResultColumnCount</property>. A cursor (iterator) is available to retrieve rows from the result set. To advance the cursor to the next row, call <method>Next</method>. The initial position of the cursor is before the first row. Next() returns 1 to indicate that it is positioned on a row or 0 to indicate that it is positioned after the last row (at the end of the result set). If the cursor is positioned after the last row, the value of ROWCOUNT indicates the number of rows contained in the result set. At any other time, ROWCOUNT contains the number of rows retrieved thus far. For more information on the result set interface refer to the <class>SQL.IResultSet</class> class.

A CALL statement result might contain output values, including a return value and any parameters defined as INPUT-OUTPUT or OUTPUT, as well as a collection of dynamic result sets. The <property>OutputColumnCount</property> property indicates the number of output values. You can retrieve individual output values by using the output value iterator - <method>NextOutputValue</method>.

The following is an example of retrieving all of the output values returned by a procedure:

if result.OutputColumnCount > 0 { set tPosition = "" set tValue = result.NextOutputValue(.tPosition) while tPosition '= "" { write !,tPosition," = ",tValue set tValue = result.NextOutputValue(.tPosition) } } else { write !,"No output values returned." }



In the above example, the value of tPosition is the position of the formal parameter whose value is returned in tValue. If the procedure declares a return value then the return value is always at position 0 (zero). Input parameters are not contained in the output values but the presence of an input parameter is reflected as a gap in the output value position.

A CALL statement can also return dynamic result sets as a collection referred to as a result set sequence. There are two mechanisms for accessing result sets - serial binding and parallel binding. Serial binding is automatically used whenever any part of its interface is invoked. The serial binding interface consists of the <property>ResultColumnCount</property> property, a private property <property>ProcCursor</property>, and the methods <method>Next</method>, <method>GetRow</method>, <method>GetRows</method>, <method>MoreResults</method>, <method>GetMetadata</method>, <method>Get</method>, <method>GetData</method>, <method>Print</method> and several internal methods. The first reference to any of the serial binding interface members triggers the first result set from the result set sequence to be bound to the ProcCursor property and also to the CurrentResult property. Subsequent references to the serial binding interface operate on that result set. When the currently bound result set is completely processed, you can invoke <method>MoreResults</method> to retrieve the next result set from the result set sequence by calling <method>NextResult</method> and then binding that result to <property>ProcCursor</property>.

The parallel binding interface is implemented as the <method>NextResult</method> method and the <property>CurrentResult</property> property. Each call to <method>NextResult</method> returns an OREF to the next result set in the collection of dynamic resultsets returned by the procedure. When all result sets have been returned then <method>NextResult</method> returns NULL (value = "" in COS). The result returned by <method>NextResult</method> is also bound to the <property>CurrentResult</property> property.

<property>CurrentResult</property> always references the most recently bound result set and it can be used for direct access to that result set, bypassing the serial binding interface. The user must be careful since both parallel binding (<method>NextResult</method>) and serial binding (automatic and <method>MoreResults</method>) affects the value of <property>CurrentResult</property>.

Member Function Documentation

◆ DisplayFormatted()

DisplayFormatted ( _.Library.String  pFormat,
_.Library.String  pFileName,
_.SQL.Manager.Messages  pMessages,
_.Library.String  pFilesUsed,
_.Library.String  pTranslateTable,
_.Library.String  pDelimiter 
)
private

Displays the contents of the result object.

If formatted display is available, then this method formats the results

using the requested format and, if appropriate, opens the formatted results using the host OS. The output is directed to one or more files and messages are placed in a result set object. All file names used are returned in an array. The arguments are as follows:

  • pFormat - The format applied to the result content. This parameter is also used to determine the file name extension.

    The supported formats are:

    • -1 = Display() format
    • 0 = XML
    • 1 = HTML
    • 2 = PDF (requires a renderer such as FOP)
    • 99 = TXT
    • 100 = CSV (actually TAB-separated)

    If pFormat is specified as any number not listed above then it will default to TXT.

    pFormat can also be specified as XML, HTML, PDF, TXT or CSV.

    NOTE: pFormat of CSV/100 is not a true comma-separated value, but instead uses TAB separated values.

  • pFileName - The base file name to be used to generate actual file names used for output. If no value is specified then a file name will be generated, using the TEMP folder defined for the InterSystems IRIS instance. This value is not expected to include an extension. An extension is added to this value to form the actual file used. Also, if nested results exist then a number is appended to the file name specified to produce a unique name for each result.
  • pMessages - Instance of a system result set class. If no value is passed then the system message result class is instantiated. This parameter is passed by reference. It is up to the caller to process the result set OREF that is returned. pMessages.Count() returns the number of messages contained in the result set. pMessages.Display() will display the messages on the current device. pMessages.DisplayFormatted() is also implemented and can be used to display the messages using the selected format.
  • pFilesUsed - This pass-by-reference parameter will contain the number of files used to display the result content and the name of each file. pFilesUsed is the number of files and pFilesUsed(file_number) is the name of the file. The sequence of the files is the same sequence as the results are processed. For simple result objects, there is a single file. For context objects that can contain result set sequences, the results are output in the order they are returned and the files used are present in pFilesUsed in that same order.
  • pTranslateTable - This is the translate table used for the output files when the format is CSV or TXT. This parameter is optional.
  • pDelimiter - The delimiter to use between columns in the export file. This parameter is optional and defaults to tab character if not specified.

Reimplemented in IResultSet.

◆ Get()

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

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

If colname is not a valid column name, this method throws a <PROPERTY DOES NOT EXIST> error.

Reimplemented in CustomResultSet, and CustomQuery.

◆ GetRow()

_.Library.Integer GetRow ( _.Library.List  Row,
_.Library.Status  sc 
)
private

Advances to the next row in the result referenced by <property>ProcCursor</property>.

Returns 0 if the cursor is at the end of the

result set. An optional argument contains a <class>Library.Status</class> value on return. This Status value indicates success or failure of the <method>GetRow</method> call. <property>SQLCODE</property> is also set by <method>GetRow</method>. The row is returned in $List format by reference in the <parameter>Row</parameter> argument. If SQLCODE'=0, Row will be null (""). This implementation is overridden by classes that implement the result set interface.

◆ GetRows()

_.Library.Integer GetRows ( _.Library.Integer  Cnt,
_.Library.List  Rows,
_.Library.Status  sc 
)
private

Advances the next <parameter>Cnt</parameter> rows in the result referenced by <property>ProcCursor</property>.

Returns 0 if the cursor is at the end of the

result set. Note, when 0 is returned, it is likely there are rows returned in the <parameter>Rows</parameter> array. An optional argument contains a <class>Library.Status</class> value on return. This Status value indicates success or failure of the <method>GetRows</method> call. <property>SQLCODE</property> is also set by GetRows. The rows are returned in an array of $List values in the <parameter>Row</parameter> array argument. If SQLCODE'=0 for a row, that will be the end of the results.

For example, suppose rset.GetRows(10,.tenrows,.sc) is called:
- If there are more then 10 rows remaining to be fetched from the result set, tenrows=10, tenrows(1)=$lb(first row's contents), ..., tenrows(10)=$lb(tenth row's contents), and <method>GetRows</method> will return 1.
- If there are 5 rows remaining to be fetched from the result set, tenrows=5, tenrows(1)=$lb(first row's contents), ..., tenrows(5)=$lb(fifth row's contents), and <method>GetRows</method> will return 0.
- If there are 0 rows remaining to be fetched from the result set, tenrows=0 and <method>GetRows</method> will return 0.

This implementation is overridden by classes that implement the result set interface.

◆ MoreResults()

_.Library.Integer MoreResults ( )
private

Invokes <method>NextResult</method> to return the next result object from a statement result object (aka 'context object') and.

updates <property>ProcCursor</property> with that value. This is called "serial binding". <property>ResultColumnCount</property> is updated to reflect the number of columns contained in the newly bound result. If a <property>ProcCursor</property> was previously set to a result object then the reference to that result object was removed. Under normal circumstances the previously bound result set is destructed.

If the new value of <property>ProcCursor</property> is a valid result object, then this method returns 1; otherwise it returns 0 to indicate that no more results are available.

Reimplemented in IProcedureContext.

◆ Next()

_.Library.Integer Next ( _.Library.Status  sc)
private

Advances to the next row in the result referenced by <property>ProcCursor</property>.

Returns 0 if the cursor is at the end of the

result set. An optional argument contains a <class>Library.Status</class> value on return. This Status value indicates success or failure of the Next call. <property>SQLCODE</property> is also set by Next. This implementation is overridden by classes that implement the result set interface.

Reimplemented in Messages, Java, Abstract, and ResultSet.

◆ NextOutputValue()

_.Library.RawString NextOutputValue ( _.Library.Integer  pPosition)
private

Returns the output value from the position following pPosition.

If the caller

passed pPosition by reference then it will contain the position corresponding to the output value returned. If the pPosition argument is NULL, then no values exist beyond the value passed by the caller and the value returned is also NULL.

The output value at position 0 is always the called routine's return value.

◆ NextResult()

_.Library.RegisteredObject NextResult ( )
private

Returns the next result object from a statement descriptor (aka 'context object').

Typically,

multiple results are only returned from an SQL invoked procedure. Such results are dynamic result sets whose metadata is not available until retrieval time. NextResult() for non-CALL statements simply returns NULL, indicating that no more results are available. For an SQL invoked procedure that returns a single preplanned result set and for SELECT statements (which return a single result set when successfully executed) this method returns the current result set object when called for the first time. Subsequent calls return a null OREF.

Reimplemented in ProcedureContext, ProcedureContext, JGWResultSet, IProcedureContext, and GTWResultSet.

◆ NormalizeObject()

_.Library.Status NormalizeObject ( )
private

Normalizes all of an object's property values by invoking the data type Normalize methods.

Many data types may allow many different representations of the same value. 
Normalization converts a value to its cannonical, or <em>normalized</em>, form.

Reimplemented from RegisteredObject.

◆ Print()

_.Library.Status Print ( _.Library.String  pDelimiter)
private

This is an abstract method.

Refer to <class>SQL.IResultSet</class> for the

concrete method implemented for result set results.