The Result class represents, among other things, the result of an SQL query:
Examples
Dim hResult As Result Dim vVariant As Variant vVariant = hResult [ Fieldname As String ] oder vVariant = hResult!Fieldname
The last two statements each return the value of a field with the specified field name in the current data record of the result object.
Result cursor
The result object is a cursor as a view of a restricted set of rows that results from the execution of the query by the DBMS. The cursor may or may not “lock” rows and tables in the database, depending on how it was executed. This lock allows only one user at a time to make guaranteed updates to the data in the database. This is a fundamental approach in the theory of DB management systems. In the DB world of Gambas, this cursor is described as read-only and read/write. Different methods for returning results from the Connection class return different cursor types: Create → Read/Write, Edit →Read/Write, Exec →Read Only and Find →ReadOnly.
The Result class has these properties:
Property | Data type | Description |
---|---|---|
Available | Boolean | Returns True if the result object contains one or more accessible database rows. |
Connection | Connection | Delivers the parent DB connection object. |
Count | Integer | Supplies the number of rows in the query result cursor exactly if the DB management system, DB driver, driver interface and Gambas interface support the return of row counts for the specific SQL query executed. ODBC connections may not be able to determine the number of data records, depending on the underlying ODBC driver. In this case, the value -1 is returned. The count starts with 0. |
Index | Integer | Delivers the index of the current data set, starting with 0. |
Max | Integer | Delivers Result.Count - 1 (as long as Count >= 0, otherwise -1 is returned). |
Fields | Result.Fields | Delivers a list of the fields of the DB result. |
Table 22.4.10.1.1 : Properties of the Result class
The Result class has these methods:
Method | Return type | Description |
---|---|---|
All ( Field As String ) | Array | Returns the value of the specified field of each result set as an array. This method is about twice as fast as the corresponding code in Gambas. |
Delete ( [ Keep As Boolean ] ) | - | Deletes the current record. If `Keep` is TRUE, the data set is not removed from the result object. |
Update ( ) | - | Updates the current data record in the database if this data record has been changed and the result is a read/write cursor. |
MoveFirst ( ) | Boolean | Moves to the first data record of the result. Returns TRUE if there are no data records in the result. |
MoveLast ( ) | Boolean | Moves to the last data record of the result. Returns TRUE if there are no data records in the result. |
MoveNext ( ) | Boolean | Moves to the next data record of the result. Returns TRUE if the result is invalid or if there is no next data record. |
MovePrevious ( ) | Boolean | Moves to the previous record of the result. Returns TRUE if the result is invalid or if there is no previous record. |
MoveTo ( Index As Integer ) | Boolean | Moves to a specific data set. Returns TRUE if the result is invalid or if the index is not valid. |
Table 22.4.10.2.1 : Methods of the Result class
This class describes all fields in a Result. The Result.Fields.Count property (data type Integer) returns the number of data records in the result of a database query.
The class has these two methods:
Method | Return type | Description |
---|---|---|
Exist ( Key As String ) | Boolean | The function returns True if the specified element exists in the result or False for the opposite. |
Refresh ( ) | - | Refreshes the overview (Result.Fields data type) of the fields in the result (of the DB query) by emptying the internal cache. |
Table 22.4.10.4.1 : Methods of the Result.Fields class