Fetch Method for LCConnection

This method obtains the next group of records from a result set. This method requires an active result set in the connection.

Defined In

LCConnection

Syntax

count = lcConnection.Fetch(destFieldlist, recordIndex, recordCount)

Parameters

Parameter

Description

destFieldlist

LCFieldlist. Fieldlist to receive the data. For each field in Fieldlist without the flag LCFIELDF_NO_FETCH, data from the corresponding field in the result set will be copied into that field. Fields in the result set and fieldlist are matched by name if the MapByName property is TRUE, by position otherwise, and are type-checked before retrieving data.

recordIndex

Long. Optional, >=1. Starting record index in the fieldlist where the record will be stored. Default is 1.

recordCount

Long. Optional, >=1. Number of records to fetch. The number of records actually fetched may be less than this number if the end of the result set was reached. While all connectors can fetch multiple records, only connectors which indicate support for Array Fetch perform a true multi-record fetch and therefore reduce network traffic and increase performance. Default is 1.

Return Value

Value

Description

count

Long. Number of records successfully fetched.

Usage Notes®

The following considerations are helpful when using the Fetch method for LCConnection.

  • Regarding the destFieldlist variable, see usage notes for the Select method for LCConnection.
  • You can achieve optimal performance by using the same fieldlist across consecutive fetches from the same target.
  • To use the recordCount parameter to retrieve multiple records, or to use a recordIndex greater than 1, you must supply a destFieldList that has already been allocated to contain multiple rows of data. Refer to the New method of LCFieldlist for details.
  • The default operation of Fetch is to map the fields in the data source to the fields in your field list by position -- the first field read goes into the first field in your fieldlist, the second field goes into the second field in the fieldlist, and so on. You can use the LCConnection.MapByName property to make LC fill in fields by matching their names with the names in the fieldlist, regardless of the order in which the data source returns them.
  • It is advisable to use the same LCFieldlist object for the Fetch as you used in the call to Select, Catalog, or Execute. This yields optimal performance.

Example

Option Public
Uselsx "*lsxlc" 

Sub Initialize
  Dim src As New LCConnection ("db2") 
 Dim fldLst As New LCFieldList
  Dim keyLst As New LCFieldList
  Dim fld As LCField
  Dim count As Integer

  ' set the appropriate properties to connect to the data source
  src.Database = "Gold"
  src.Userid = "JDoe"
  src.Password = "xyzzy"
  src.Metadata = "customer"

  src.Connect

  ' the FIELDNAMES property of a connection is used to
  ' specify which fields should be used in the result set
  ' if no names are listed, then all fields will be fetched

  src.FieldNames = "ContactName, AccountManager"

  ' the select statement may be called with 'Nothing' as
  ' the keylist parameter. this causes all records to be
  ' selected for the result set.
  ' by creating a keylist with one or more keys, conditions,
  ' and values, tighter control of the result set is possible
  ' here we want to indicate all account managers except
  ' number 200

  ' NOTE: to indicate that a field is a key, the LCFIELDF_KEY flag
  ' must always be included in the value of the connection's flags

  Set fld = keyLst.Append ("ACCOUNTMANAGER", LCTYPE_INT)
  fld.Flags = LCFIELDF_KEY_NE Or LCFIELDF_KEY
  fld.Value = 200

  ' the selection statement builds an international result set which
  ' is later accessed with successive fetches
  If (src.Select (keyLst, 1, fldLst) = 0) Then
    Print "No data were located."
    End
  End If
  Set fld = fldLst.Lookup ("CONTACTNAME")
  Print "the 'contact names' stored in the table are:"
  ' fetch a record from the result set
  While (src.Fetch (fldLst) > 0)
    count = count + 1
    Print "     record #" & Cstr(count) & " = '" & fld.text(0) & "'"
  Wend
  If (count = 0) Then Print "The table contains no records."
End Sub

Example Output

the 'contact names' stored in the table are:
     record #1 = 'Peter Soames
     record #2 = 'Trent Kent'
     record #3 = 'Joan Lawrens'

Fetch Method for LCConnection for the Connector for DB2®

This method retrieves one or more records from the current result set.

The function requires that a result set was previously produced by the LCConnection methods Execute, Select, Call, or Catalog. The result set data is type-checked against and then moved into the supplied DestFieldlist. Fields with the flag LCFIELDF_NO_FETCH set are not fetched.

The property MAP_NAME indicates whether to map fields in DestFieldlist and the result set by name or position. Handling of both mapping and field flags is implicitly done by calling LCFieldlistMerge with the result set field names as NameFieldlist, DestFieldlist as DataFieldlist, and MergeFlags LCMERGEF_NAME_LOSS, LCMERGEF_FETCH, and optionally (depending on the MAP_NAME property) LCMERGEF_MAP_NAME.

For non-scrollable result sets, each record in the result set is fetched exactly once and only in a forward direction. LCFAIL_END_OF_DATA should be returned when the last call to LCXFetch retrieved the last record in the result set. If at least one record was fetched but the end of the result set was reached before fetching RecordCount records, LCSUCCESS is returned.

For scrollable result sets produced by LCXExecute or LCXSelect with the property LCTOKEN_SCROLLABLE set, backwards fetching is performed starting with the record before the most recently fetched record and moving backwards in the result set.