LCFieldlist の MapName メソッド

このメソッドは、フィールドの名前を変更してマップします。このメソッドは、ソースとターゲットのフィールド名が異なる場合にフィールドをマッピングするときに使用します。これにより、フィールドの順序を変更でき、一部のフィールドを除外することもできます。

このメソッドでは、新しい LCField オブジェクトは作成されません。代わりに、ターゲットリストにはソースリストに含まれているのと同じ LCField オブジェクトへの参照が追加されます。一方のリストのフィールドに値を割り当てると、もう一方のリストの対応するフィールドにも同じ値が自動的に割り当てられます。これは、2 つのリストが同じ記憶域を共有するためです。これを利用すると、フィールドリスト間で値をコピーしなくても、1 つのコネクションからフェッチしたレコードを即座に他のコネクションに書き出すことができます。

定義位置

LCFieldlist

構文

Call destList. MapName (sourcelist, nameList, mapList)

パラメータ

パラメータ

説明

sourcelist

LCFieldlist。マップするフィールドが含まれているフィールドリストです。

nameList

String 型。sourceList に含まれている元のフィールドの名前をカンマで区切って指定したリストです。sourceList のフィールドをすべて指定する必要はありません。また、順序が異なっていてもかまいません。

mapList

String 型。新しいフィールド名を destList での順にカンマで区切って指定したリストです。リストに含まれるフィールド名の数は、nameList と同じでなければなりません。また、各フィールドは nameList の対応する位置にあるフィールドにマップされます。例えば、nameList に「a、b、c」、mapList に「d、e、f」が含まれている場合、sourceList のフィールド「a」は destList のフィールド「d」に対応し、フィールド「b」はフィールド「e」にというように対応します。

Option Public
Uselsx "*lsxlc" 
Sub Initialize
  Dim session As New LCSession
  Dim srcCon As New LCConnection ("db2") 
Dim destCon As New LCConnection ("notes")
  Dim fetchLst As New LCFieldList
  Dim insertLst 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
  srcCon.FieldNames = "ContactName, CompanyCity, CompanyState"
  If (srcCon.Select (Nothing, 1,  fetchLst) <> 0) Then
    ' map the result set from the SELECT with the desired names in the destination.
    Call insertLst.MapName (fetchLst, _
    "ContactName, CompanyCity, CompanyState", _
    "Name, City, State")
      ' set the property MapbyName on the target.
    ' this is necessary if the fields in the form are
    ' (or might be) in different order than they appear in destCon.
    destCon.MapByName = True
      While (srcCon.Fetch (fetchLst, 1, 1) > 0)
      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

出力例

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