LCFieldlist の Map メソッド

このメソッドは、フィールドリストのフィールド参照を別のフィールドリストにコピーします。CopyRef メソッドに似ていますが、新しい参照を作成するフィールド名を指定する点が異なります。

Map を使用した後は、コピー元およびコピー先のリストに同じ LCField オブジェクトに対するフィールド参照が含まれます。この呼び出しでは、新しい LCField オブジェクトは作成されません。

コピー元とコピー先のフィールド名が同じで、フィールドの順序を変更する場合や、一部のフィールドを除外する場合は、このメソッドを使用してフィールドのマッピングを行います。コピー元とコピー先のフィールド名が異なる場合は、MapName を使用します。

定義位置

LCFieldlist

構文

Call destList. Map (baseFieldList, nameList)

パラメータ

パラメータ

説明

srcList

LCFieldlist。マップするフィールドリストです。

nameList

String 型。srcList のフィールド名を、新たにマップする順序で、カンマで区切って指定します。

使用法

destList の値は Nothing であってはなりません。常にオブジェクトが必要です (New メソッドで作成された直後のオブジェクトが望ましい)。destList リストに既にフィールドが含まれている場合は、Map メソッドにより破棄されます。

Option Public
Uselsx "*lsxlc" 
Sub Initialize
  Dim session As New LCSession
  Dim srcCon As New LCConnection ("db2") 
  Dim fldLst As New LCFieldList
  Dim fetchLst As New LCFieldList
  Dim count As Long
  Dim cname As LCField
  Dim ccity As LCField
  Dim cstate As LCField
  ' set the appropriate properties to connect to the data sources
  srcCon.Database = "Gold"
  srcCon.Userid = "JDoe"
  srcCon.Password = "xyzzy"
  srcCon.Metadata = "customer"
  srcCon.Connect
  ' perform a select and get the records with
  ' the fields wanted, in our fldLstRecord object
  If (srcCon.Select (Nothing, 1,  fldLst) <> 0) Then
    Print "Table contains " & fldLst.FieldCount & " fields."
    ' now map the fields of interest, in the order needed,
    ' discarding fields that we're not interested in.
    Call fetchLst.Map (fldLst, "ContactName, CompanyCity, CompanyState")
    Print "Fetch field list contains " & fetchLst.FieldCount & " fields."
    Set cname = fetchLst.GetField (1)
    Set ccity = fetchLst.GetField (2)
    Set cstate = fetchLst.GetField (3)
    REM fetch a record from the result set
    srcCon.MapByName = True ' because the fields in the result set are not in this order.
      Print "Fetching ContactName, CompanyCity, and CompanyState fields"
    While (srcCon.Fetch (fetchLst, 1, 1) > 0)
      count = count + 1
      Print Cstr(count); Tab(3); cname.Text(0); Tab(28); _
      ccity.Text(0); Tab(42); cstate.Text(0)
    Wend
  End If
End Sub

出力例

Table contains 8 fields.
Fetch field list contains 3 fields.
Fetching ContactName, CompanyCity, and CompanyState fields:
1 Peter Jay 		Okend	NH
2 Trent Kent		Farmtown	RI
3 Joan Thomast	Lawrens	MN