%Library.ResultSet
class %Library.ResultSet extends %Library.AbstractResultSet
Cache Dynamic SQL is the preferred mechanism for preparing and executing dynamic SQL statements. Please refer to %SQL.Statement for more information. %Library.ResultSet continues to be used and supported.
The %ResultSet class provides a way to use the results of class queries from within a Caché ObjectScript application. It is similar in operation to the ResultSet objects provided with the ActiveX and Java bindings.
You can use a %ResultSet object as follows:
Note you can bind a %ResultSet object to a query by either
a) setting the ClassName and QueryName
properties or b) passing a string containing the class name and query name (separated
by a :) to the
; 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() }
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
Property Inventory
Method Inventory
- %CloseCursor()
- %DispatchGetProperty()
- %Execute()
- %Get()
- %GetData()
- %MetadataGet()
- %Next()
- %PrepareMetaData()
- %ResultColumnCountGet()
- %SendDelimitedRows()
- %SendODBC()
- ClassNameSet()
- Close()
- ContainsId()
- Execute()
- Get()
- GetColumnCount()
- GetColumnExtInfo()
- GetColumnHeader()
- GetColumnName()
- GetColumnType()
- GetData()
- GetDataByName()
- GetExtent()
- GetODBCInfo()
- GetObject()
- GetParamCount()
- GetParamName()
- GetStatementType()
- Next()
- Prepare()
- QueryIsValid()
- RuntimeModeGet()
- RuntimeModeSet()
- SetIdInfo()
- Test()
Properties
; 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")),! }
- 0 for LOGICAL mode.
- 1 for ODBC mode.
- 2 for DISPLAY mode.
- "" to use the process wide $zu(115,5) value.
Methods
If name is not a valid column name, this method returns an empty string.
The arguments p1... supply the value of any parameters the query may have.
This method sets the %SQLCODE property if an error is reported. The value of %SQLCODE is computed from the status value and is not set to the value of the public SQLCODE variable. The %Message, %ROWCOUNT and %ROWID 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.
If name is not a valid column name, this method returns an empty string.
Using the Data multidimensional property to
access the fields is faster than using this method call.
1 | BINARY | |
2 | DATE | |
3 | DOUBLE | |
4 | HANDLE | |
5 | INTEGER | |
6 | LIST | |
7 | LONGVARCHAR | |
8 | TIME | |
9 | TIMESTAMP | |
10 | VARCHAR | |
11 | STATUS | |
12 | BINARYSTREAM | |
13 | CHARACTERSTREAM | |
14 | NUMERIC | |
15 | CURRENCY | |
16 | BOOLEAN | |
17 | OID | |
18 | BIGINT | |
19 | FDATE | |
20 | FTIMESTAMP |
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.
1 | SELECT |
2 | INSERT (also 'INSERT OR UPDATE') |
3 | UPDATE |
4 | DELETE |
5 | COMMIT |
6 | ROLLBACK |
7 | GRANT |
8 | REVOKE |
9 | CREATE TABLE |
10 | ALTER TABLE |
11 | DROP TABLE |
12 | CREATE VIEW |
13 | ALTER VIEW |
14 | DROP VIEW |
15 | CREATE INDEX |
16 | ALTER INDEX (Not supported) |
17 | DROP INDEX |
18 | CREATE ROLE |
19 | DROP ROLE |
20 | SET TRANSACTION |
21 | START TRANSACTION |
22 | %INTRANSACTION |
23 | %BEGTRANS (Alias for START TRANSACTION) |
24 | %INTRANS (Alias for %INTRANSACTION) |
25 | GET (Not supported) |
26 | SET OPTION |
27 | STATISTICS (UPDATE STATISTICS, not supported)) |
28 | %CHECKPRIV |
29 | CREATE USER |
30 | ALTER USER |
31 | DROP USER |
32 | %CHECKPRIV (SQL Admin Privilege) |
33 | GRANT (SQL Admin Privilege) |
34 | REVOKE (SQL Admin Privilege) |
35 | CREATE FUNCTION |
36 | CREATE METHOD |
37 | CREATE PROCEDURE |
38 | CREATE QUERY |
39 | DROP FUNCTION |
40 | DROP METHOD |
41 | DROP PROCEDURE |
42 | DROP QUERY |
43 | CREATE TRIGGER |
44 | DROP TRIGGER |
45 | CALL |
46 | SAVEPOINT |
47 | LOCK TABLE |
48 | UNLOCK TABLE |
49 | CREATE DATABASE |
50 | DROP DATABASE |
51 | USE DATABASE |
"" | Anything not list above |
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"),! }
Inherited Members
Inherited Properties
Inherited Methods
- %AddToSaveSet()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %CreateSnapshot()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %Display()
- %DisplayFormatted()
- %Extends()
- %GetMetadata()
- %GetParameter()
- %IsA()
- %IsModified()
- %New()
- %NormalizeObject()
- %ObjectModified()
- %OriginalNamespace()
- %PackageName()
- %Prepare()
- %Print()
- %RemoveFromSaveSet()
- %SerializeObject()
- %SetModified()
- %ValidateObject()
- RunQuery()