User Tools

Site Tools


Sidebar

Databases

k22:k22.4:k22.4.10:start

22.4.10 Classes Result and Result.Fields (gb.db)

The Result class represents, among other things, the result of an SQL query:

  • The class cannot be created.
  • This class behaves like a read/write array.
  • This class can be enumerated with the keyword FOR EACH.

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.

22.4.10.1 Properties of the Result class

The Result class has these properties:

PropertyData typeDescription
AvailableBooleanReturns True if the result object contains one or more accessible database rows.
ConnectionConnectionDelivers the parent DB connection object.
CountIntegerSupplies 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.
IndexIntegerDelivers the index of the current data set, starting with 0.
MaxIntegerDelivers Result.Count - 1 (as long as Count >= 0, otherwise -1 is returned).
FieldsResult.FieldsDelivers a list of the fields of the DB result.

Table 22.4.10.1.1 : Properties of the Result class

22.4.10.2 Methods of the Result class

The Result class has these methods:

MethodReturn typeDescription
All ( Field As String )ArrayReturns 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 ( )BooleanMoves to the first data record of the result. Returns TRUE if there are no data records in the result.
MoveLast ( )BooleanMoves to the last data record of the result. Returns TRUE if there are no data records in the result.
MoveNext ( )BooleanMoves to the next data record of the result. Returns TRUE if the result is invalid or if there is no next data record.
MovePrevious ( ) BooleanMoves 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 )BooleanMoves 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

22.4.10.3 Properties of the Result.Fields 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.

22.4.10.4 Methods of the Result.Fields class

The class has these two methods:

MethodReturn typeDescription
Exist ( Key As String )BooleanThe 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

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k22/k22.4/k22.4.10/start.txt · Last modified: 27.04.2024 by emma

Page Tools