LCConnection の Execute メソッド

このメソッドは Connector 固有の構文を使用したステートメントを実行します。例えばリレーショナルデータベース用 Connector では SQL ステートメントを使用します。このメソッドは、例えば結果セットを作成するために DB2® SQL ステートメントを実行します。

定義位置

LCConnection

構文

count = lcConnection.Execute(statement, destFieldlist)

パラメータ

パラメータ

説明

statement

String 型。Connector に対して定義された構文で実行するためのステートメント。構文については、各 Connector のドキュメントを参照してください。

destFieldList

Long。LCFieldlist。実行結果セットのメタデータを格納するフィールドリスト。結果セット内のフィールドがこのフィールドリストに追加されます。結果セットのメタデータが必要ない場合は「Nothing」を使用します。

戻り値

説明

count

Long。このステートメントで選択または影響を受けたレコード数。Connector によってレコード数の判断がつかない場合は、定数 LCCOUNT_UNKNOWN が返されます。

Option Public
Uselsx "*lsxlc" 

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

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

  src.Connect

  ' now connected, we can execute a selection statement
  If (src. Execute ("SELECT * from customer",  fldLst) = 0) Then
    Print "No records were fetched."
    End
  End If
  Set fld = fldLst.Lookup ("CONTACTNAME")
  Print "the 'contact names' stored in the table are:"

  ' fetch each 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 "No records were fetched."
End Sub

出力例

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