BBjRecordSet::insert

Description

In BBj 4.0 and higher, this method inserts a new BBjRecordData buffer to the BBjRecordSet.

Syntax

Return Value

Method

void

insert(BBjRecordData recordData)

Parameters

Variable

Description

recordData

Specifies a BBjRecordData object.

Return Value

None.

Remarks

Use this method to insert a new record to the recordset. Attempting to insert a record that already exists in the recordset generates an error. To update an existing record, use BBjRecordSet::update. After calling this method, the current record is unchanged. That is to say after inserting a record, you must seek to that newly inserted record before attempting to update. Note that the inserted record may not be visible within the recordset if, for instance, the select statement would not have included it in the original result set.

Example

rem ' Insert a new RecordData to a RecordSet

rem ' First, create a data file
FILENAME$="BBjRecordSet.dat"
MODES$=""
TEMPLATE$="STATE:C(2),NAME:C(16* = )"
erase FILENAME$,err=*next
mkeyed FILENAME$,[0:1:2],0,32
channel = unt
open (channel)FILENAME$
dim REC$:TEMPLATE$

rem ' Load the file with state codes and names
while 1
    dread rec.state$,rec.name$,END=*break
    write record (channel)rec$
wend
close (channel)

rem ' Create a file-based BBjRecordSet
RecordSet! = BBJAPI().createFileRecordSet(FILENAME$,MODES$,TEMPLATE$)

rem ' Get an empty RecordData
RecordData! = RecordSet!.getEmptyRecordData()

rem ' Set the state code and name
RecordData!.setFieldValue("state","AT")
RecordData!.setFieldValue("name","Atlantis")

rem ' Print the RecordData
print "The new RecordData is:",'LF',RecordData!,

rem ' Write the changes out to disk
RecordSet!.insert(RecordData!)
print "Wrote the new RecordData to disk."

rem 'WE MUST MOVE TO NEW RECORD BEFORE DOING UPDATES to it.
RecordSet!.seek(RecordData!,1)
RecordData! = RecordSet!.getCurrentRecordData()
RecordData!.setFieldValue("name","Atlantis Proper")
RecordSet!.update(RecordData!)
print "Updated new record, AFTER moving to it."
stop
DATA "AK","Alaska"
DATA "AL","Alabama"
DATA "WI","Wisconsin"
DATA "WV","West Virginia"
DATA "WY","Wyoming"

See Also

BBjAPI

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.