%SQL.IResultSet
abstract class %SQL.IResultSet extends %SQL.StatementResult, %ResultSet.QuerySuper
A result set can be returned by executing a SELECT statement or a CALL statement.
A result set is a type of statement result (%SQL.StatementResult). A result set is a collection of rows, all of the same ROWTYPE. The ROWTYPE is described by the result set's metadata. The result set metadata can be retrieved by calling %GetMetadata(). The OREF returned by %GetMetadata() references an instance of %SQL.StatementMetadata.
A result set has an iterator that is initially positioned before the first row. The iterator is repositioned by calling %Next(). %Next() returns one (1) if the iterator is positioned at the next row or zero (0) indicating that the iterator is positioned after the last row.
Column values from the current row can be accessed by column name by calling %Get() or by column position by calling %GetData().
SAMPLES>set result = ##class(%SQL.Statement).%ExecDirect(,"select Name, SSN, DOB from Sample.Person where Age < 50") SAMPLES>write result.%SQLCODE 0 SAMPLES>write result.%Next() 1 SAMPLES>write result.%Get("Name") Zevon,Patricia L. SAMPLES>write result.%GetData(1) Zevon,Patricia L. SAMPLES>write result.Name Zevon,Patricia L.Column values can also be accessed by property name. The name of the property corresponding to a column is based on the column name. If the column name is not a valid object identifier then it is transformed into a valid object identifier. The column can still be accessed as a property through dynamic dispatch. If there are questions about the property name that corresponds to a particular column then the statement can define an alias for the column that is a valid object identifier.
If the result set is the result of executing a statement prepared with %ObjectSelectMode = 1 then any column whose type class is a swizzleable class is bound to a swizzleable property.
set tStatement = ##class(%SQL.Statement).%New() set tStatement.%ObjectSelectMode = 1 set tSC = tStatement.%Prepare("select %ID as ID, Spouse as Spouse from Sample.Person where Spouse IS NOT NULL") set tResult = tStatement.%Execute() if 'tResult.%SQLCODE { if tResult.%Next() { write "Person ID: ",tResult.ID.%Id()," Name: ",tResult.ID.Name," Spouse Name: ",tResult.Spouse.Name,! } }
Executing this code in the SAMPLES namespace generates output similar to:
Person ID: 101 Name: Donaldson,Nataliya J. Spouse Name: Grabscheid,Dan L.
The number of rows returned from a result set is available in the %ROWCOUNT property, which is inherited from the %SQL.StatementResult superclass.
Property Inventory
Method Inventory
- %DispatchMethod()
- %Display()
- %DisplayFormatted()
- %DisplayMarkDown()
- %GetClientMetadata()
- %GetMetadata()
- %GetStatement()
- %Print()
- getSelectMode()
Parameters
Properties
Methods
Display the contents of the result object. If formatted display is available then format the results using the requested format and, if appropriate, open 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.
Parameters
Name | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pFormat |
The format applied to the result content. This parameter is also used to determine the file name extension. Supported formats are:
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. |
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 Court | Sarasota | NY | 12866 |
Huff,Stephen A. | 548 Washington Blvd | Brownfield Center | MD | 53436 |
Sands,Jeep Q. | 7298 Washington Drive | Xavier | WY | 23685 |
Inherited Members
Inherited Properties
- %CurrentResult
- %Message
- %OutputColumnCount
- %ROWCOUNT
- %ROWID
- %ResultColumnCount
- %SQLCODE
- %StatementType
- %StatementTypeName
Inherited Methods
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %Extends()
- %Get()
- %GetData()
- %GetParameter()
- %GetRow()
- %GetRows()
- %IsA()
- %IsModified()
- %MoreResults()
- %New()
- %Next()
- %NextOutputValue()
- %NextResult()
- %NormalizeObject()
- %ObjectModified()
- %OriginalNamespace()
- %PackageName()
- %SerializeObject()
- %SetModified()
- %ValidateObject()
- Close()
- Fetch()
- FetchRows()
- GetInfo()
- GetODBCInfo()