Delete Record LSX Example

Author: Tripp W Black

Created: 05/20/2002 at 02:40 PM

 

Category:
Notes Developer Tips
LSX (LotusScript Extensions/Connectors)

From the Lotus EI web site.
Delete record set example.

Domino Connector LSX Sample
Select and Remove method

This example shows how to use the Select method with a key and how to perform a Remove of a record based on the key. It sets properties and then connects. The key value is assigned and the key fieldlist is created. The select is done and the record that matches the key is put into the result set. The record is written to the target using fetch and insert . Finally the record is removed from the source.

Dim session As New LCSession
Dim srccon As New LCConnection ("db2")
Dim destcon As New LCConnection ("notes")
Dim fldLstRecord As New LCFieldList (1, 0)
Dim keyLst As New LCFieldList(1, 0)
Dim conFld As New LCField (LCTYPE_TEXT, 1)
Dim keySearch As New LCField(LCTYPE_TEXT, 1)
Dim keyName As String
Dim count As Long
Dim mb As Long
Dim wintitle As String

On Error Goto ErrorHandler
mb = MB_IconInformation + MB_OK
wintitle = "Connection Select and Remove Example"

REM set the appropriate properties to connect to the data sources
srcCon.Database = "Sample"
srcCon.Userid = "dbinst1"
srcCon.Password = "example"
srcCon.Metadata = "dbinst1.customer"

destCon.Server = "MyDomino"
destCon.Database = "qe\testdata\newdb.nsf"
destCon.Metadata = "newcustomer"

REM connect to the two data sources
srcCon.Connect
destCon.Connect

REM use a key to find certain records to remove
keyName = "CONTACTNAME"
Set keySearch = keyLst.Append (keyName, LCTYPE_TEXT)
keySearch.Flags = LCFIELDF_KEY
keySearch.text = "Me"

REM now connected, we can perform a select and get the record based on the key

count = srcCon.Select (keyLst, 1, fldLstRecord)


REM now create the metadata. If it exists already, ignore the error (LCFAIL_DUPLICATE).
REM must do this after the select so there is a valid fieldlist.
On Error LCFAIL_DUPLICATE Resume Next
Call destCon.Create (LCOBJECT_METADATA, fldLstRecord)

If count <> 0 Then

REM now fetch a record from the result set
count = srcCon.Fetch (fldLstRecord, 1, 1)
REM if there is a record that matched the key
If count <> 0 Then
REM now insert the record into the target and fetch the next, looping until all records have been inserted
count = destcon.Insert (fldLstRecord, 1, 1)
count = srccon.Fetch (fldLstRecord, 1, 1)
REM now remove the record from the source

count = srccon.Remove(fldLstRecord, 1, 1)

End If
End If
End

ErrorHandler:
Dim msg As String
Dim msgcode As Long
Dim status As Integer
Dim result As String

If session.status <> LCSUCCESS Then
Call session.GetStatus (result, msgcode, msg)
Else
result = "Error " & Err() & ": " & Error()
End If

Messagebox (result), mb, wintitle

End


previous page