Remove Method for LCConnection

This method performs either a writeback result set remove or a keyed remove of records in the external system.

Defined In

LCConnection

Syntax

count = lcConnection.Remove (keyFieldlist, recordIndex, recordCount)

Parameters

Parameter

Description

keyFieldlist

LCFieldlist. Fieldlist containing keys for a keyed remove only. For each field in the Fieldlist with the flag LCFIELDF_KEY set, only records in the connection with the same value for that field are deleted. Use LCFIELDF_KEY_XXX flags as inequality keys, if desired. Zero or more key fields may be supplied, with zero keys resulting in all records in the target being deleted. Fields in the connection and fieldlist are matched by name if the MapByName property is TRUE, by position otherwise.

recordIndex

Long, >=1. Optional. Starting record index in the fieldlist. The default is 1.

recordCount

Long, >=1. Optional. Number of keyed remove operations to perform. RecordCount must be 1 for a writeback remove but may be greater to perform multiple keyed updates with different update and key values. The default is 1.

Return Value

Value

Description

count

Long. Number of records successfully removed. If this number cannot be determined, the constant LCCOUNT_UNKNOWN is returned.

Usage Notes®

You can achieve optimal performance by using the same fieldlist across consecutive removes from the same target.

The property Writeback indicates whether to perform a writeback or keyed remove:

  • Writeback remove: If the Writeback property is set True, this method removes the most recently fetched record from the writeback result set (the result set produced by LCConnection.Execute, LCConnection.Select or LCConnection.Call with the Writeback property set). The key field list and Condition property do not have any effect on a Writeback operation.
  • Keyed remove: Removes all records in the supplied metadata with field values matching all fields in the fieldlist that have the LCFIELDF_KEY field flag set. If a value is specified for the property Condition, this will be included in the key search criteria. This value must be in a syntax valid for the relevant connector.

When using inequality key flags GT, LT, and NE, it is important to remember that the default of no flags is equal. The following combinations are valid for inequality flags:

  • equal to LCFIELDF_KEY
  • greater than or equal to LCFIELDF_KEY + LCFIELDF_KEY_GT
  • less than or equal to LCFIELDF_KEY + LCFIELDF_KEY_LT
  • not equal to LCFIELDF_KEY + LCFIELDF_KEY_NE
  • greater than LCFIELDF_KEY + LCFIELDF_KEY_GT + LCFIELDF_KEY_NE
  • less than LCFIELDF_KEY + LCFIELDF_KEY_LT + LCFIELDF_KEY_NE
  • string pattern matching LCFIELDF_KEY + LCFIELDF_KEY_LIKE

If you supply more than one key field comparison in your keyFieldList, effectively you are "and"ing the tests -- LCConnection will remove records that meet all the tests. Likewise if you supply one or more key tests and an additional test in the Condition property.

LCConnection does not directly support logical "or" operations of multiple conditions. You can, however, execute any query using LCConnection.Execute, or construct an "or" type query in the Condition field, using the query language supported by the connector.

The rules for pattern matching in a "like" comparison vary depending on the connector. Consult your database documentation for details.

Example

Option Public
Uselsx "*lsxlc" 

Sub Initialize
  Dim src As New LCConnection ("db2") 
 Dim keyList As New LCFieldList
  Dim key As LCField

  ' set the appropriate properties to connect to the data sources
  src.Database = "Gold"
  src.Userid = "JDoe"
  src.Password = "xyzzy"
  src.Metadata = "customer"
  src.MapByName = True
  ' connect to the two data sources
  src.Connect

  ' use a key to find certain records to remove
  Set key =  keyList.Append ("ACCOUNTMANAGER", LCTYPE_INT)
  key.Flags = LCFIELDF_KEY
  key.value = 200

  ' we can perform a keyed delete of the matching record in the table
  Print "Removed " & Cstr (src.Remove (keyList)) & " record(s)"
End Sub

Example Output

Removed 2 record(s).

Remove Method for LCConnection for DB2®

This method deletes records from a writeback result set or keyed search in the METADATA object in DB2®.

The LCXRemove method operates in one of two modes, depending if the WRITEBACK property is set and there is a current result set that supports writeback.

A writeback result set is one in which modifications can be made directly to the most recently Fetched record. This is often more efficient than a keyed operation. To support writeback, the WRITEBACK property must be set prior to producing the result set with Execute or Select (Call and Catalog do not support writeback result sets). This produces a writeback result set. Once a record has been Fetched, that record is available for writeback Update and Remove operations. When these methods are called with the WRITEBACK property set, the operation affects the most recently Fetched record. If the WRITEBACK property is not set, these methods operate using keys, even if the result set is a writeback result set.

Non-writeback Removes

One or more keyed removes are performed against the metadata indicated by the METADATA property. For each record used as key values, a keyed remove constructed from those key values should be performed. Any value for the CONDITION property should be included in the search criteria.

Only fields with the flag LCFIELDF_KEY should be used as key values.

The property MAP_NAME indicates whether to map fields in KeyFieldlist and the target metadata by name or position. Handling of both mapping and field flags is implicitly handled by calling LCFieldlistMerge with the target metadata field names as NameFieldlist, KeyFieldlist as DataFieldlist, and MergeFlags LCMERGEF_NAME_LOSS, LCMERGEF_REMOVE, LCMERGEF_KEY, and optionally (depending on the MAP_NAME property) LCMERGEF_MAP_NAME.

Writeback Removes

There must be a current result set which supports writeback operations and a previous LCXFetch from that result set. The last document fetched by the most recent LCXFetch call is deleted.