Merge Method for LCFieldlist

This method merges two fieldlists, copying the names from one and taking the field objects from another to fill in a third mapping fieldlist. Use this method for field mapping operations when you either have a name fieldlist already built and/or you need to use fieldlist flags.

Defined In

LCFieldlist

Syntax

Call destList.Merge (nameFieldList, dataFieldList, mergeFlags)

Parameters

Parameter

Description

nameFieldlist

LCFieldlist. Source fieldlist containing the field names for the new fieldlist. The data types and values of the fields in the list are ignored.

dataFieldlist

LCFieldlist. Source fieldlist containing the referenced data for the new fieldlist.

mergeFlags

Long. By default, both fieldlists must have the same number of fields, and those fields are mapped by position (first to first, second to second, and so on). You can use mergeFlags to alter this default behavior, with zero or more of the following values, ORed together:

LCMERGEF_MAP_NAME -- Match source and destination fields by field name instead of by position.

LCMERGEF_DATA_LOSS -- Ignore fields in DataFieldlist that have no corresponding field in nameFieldlist.

LCMERGEF_NAME_LOSS -- Ignore fields in nameFieldlist that have no corresponding field in dataFieldlist.

LCMERGEF_FETCH -- Ignore fields with the LCFIELDF_NO_FETCH flag set.

LCMERGEF_INSERT -- Ignore fields with the LCFIELDF_NO_INSERT flag set.

LCMERGEF_UPDATE -- Ignore fields with the LCFIELDF_NO_UPDATE flag set.

LCMERGEF_REMOVE -- Ignore fields with the LCFIELDF_NO_REMOVE flag set.

LCMERGEF_CREATE -- Ignore fields with the LCFIELDF_NO_CREATE flag set.

LCMERGEF_DROP -- Ignore fields with the LCFIELDF_NO_DROP flag set.

LCMERGEF_KEY -- Include fields with the LCFIELDF_KEY flag set.

Usage Notes®

This data obtained from the dataFieldList consists of references to that list's LCField objects. The field name isn't stored in the LCField, so different field lists can refer to the same LCField object by different names. This method does not create new LCField objects.

What this method does is essentially no different from what you could do with the Map method; it just gets its fieldnames from a LCFieldlist object instead of from a comma-delimited string. The data values and data types of fields in the nameFieldList are ignored.

If destList already contains fields, the Merge method will discard them.

Example

Option Public
Uselsx "*lsxlc" 
Sub Initialize
  Dim session As New LCSession
  Dim srcCon As New LCConnection ("db2
  Dim destCon As New LCConnection ("notes")
  Dim fldLst As New LCFieldlist
  Dim fetchLst As New LCFieldlist
  Dim insertLst As New LCFieldlist
  Dim dataLst As New LCFieldlist
  Dim nameLst As New LCFieldlist
  Dim count As Long
  REM set the appropriate properties to connect to the data sources
  srcCon.Database = "Gold"
  srcCon.Userid = "JDoe"
  srcCon.Password = "xyzzy"
  srcCon.Metadata = "customer"
  destCon.Server = "Rainbow"
  destCon.Database = "Gold"
  destCon.Metadata = "customer"
  REM connect to the two data sources
  srcCon.Connect
  destCon.Connect
  REM we can perform a select and get the records with the fields we want 
  REM in our fldLstRecord object
  If (srcCon.Select (Nothing, 1,  fldLst) <> 0) Then
    REM first we identify the data fields to fetch and order them
    Call dataLst.Append ("CONTACTNAME", LCTYPE_TEXT)
    Call dataLst.Append ("COMPANYCITY", LCTYPE_TEXT)
    Call dataLst.Append ("COMPANYSTATE", LCTYPE_TEXT)
    Call fetchLst.Merge (dataLst, fldLst, LCMERGEF_MAP_NAME Or LCMERGEF_DATA_LOSS)
    REM now we need to do a merge of the fields being fetched with the 
    REM names of the fields being stored
    Call nameLst.Append ("Name", LCTYPE_TEXT)
    Call nameLst.Append ("City", LCTYPE_TEXT)
    Call nameLst.Append ("State", LCTYPE_TEXT)
    Call insertLst.Merge (nameLst, fetchLst, 0)
      REM set the property Map by Name on both data sources
    srcCon.MapByName = True
    destCon.MapByName = True
      REM fetch a record from the result set
    While (srcCon.Fetch (fetchLst, 1, 1) > 0)
      REM now insert the record into the target and fetch the next, 
      REM looping until all records have been inserted
      count = count + destCon.Insert (insertLst, 1, 1)
    Wend
    Print "Transferred " & count & " records from DB2, to Notes"
    Print "Field mapping from (DB2 column name to Notes Field name):"
    Print "     ContactName   -->  Name"
    Print "     CompanyCity   -->  City"
    Print "     CompanyState  -->  State"
  End If
End Sub

Example Output

Transferred 3 records from DB2, to Notes
Field mapping from (DB2 column name to Notes Field name):
     ContactName	-->  	Name
     CompanyCity	-->  	City
     CompanyState	-->  	State