Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Insert record
Tue, Jul 31 2007 4:39 AMPermanent Link

Tomas
Hi,

Sometimes I need to return deleted record in database.
I am using AfterDeleteTrigger event to do this but actually I don't know how to do this.
I know that CurrentRecord: TDBISAMRecord keeps values of deleted record in OldValues.
It would be easy to assign OldValues to NewValues and add TDBISAMRecord to table, unfortunately
there is no option to add TDBISAMRecord object to record or maybe there is?. So I need to use SQL to insert record back to table.

I have tried to use code below, but got error "Could not convert variant of type (String) into type (Double)" and this is logical because I can't mix
many field types into one string.

Could anyone suggest solution?

procedure TdmEngine.DBISAMEngineAfterDeleteTrigger(Sender: TObject;
 TriggerSession: TDBISAMSession; TriggerDatabase: TDBISAMDatabase;
 const TableName: string; CurrentRecord: TDBISAMRecord);

.....

 if SameText(TableName, 'topic') = true then
 begin
 UpdTableName := 'topic';
   for i := 0 to CurrentRecord.FieldCount-1 do
   begin
     aFld := CurrentRecord.Fields[i];
     if (aFld.FieldKind = fkData) then
     begin
       if aFldNames > '' then
       begin
         aFldNames := aFldNames + ',';
         aFldValues := aFldValues + ',';
       end;
       aFldNames := aFldNames + aFld.FieldName;
       aFldValues := aFldValues +  aFld.OldValue;
     end;
   end;
   if aFldNames = '' then abort;
   qTopic.SQL.Text := 'INSERT INTO ' + UpdTableName + '(' + aFldNames + ') VALUES(' + aFldValues + ')';
......

Regards,
Tomas
Tue, Jul 31 2007 8:36 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Tomas,

<< Could anyone suggest solution?  >>

Do this:

1) Declare and create a local TDBISAMTable component that references the
table that you want to insert into.

2) Put the TDBISAMTable into insert mode by calling the Insert method.

3) Loop through the fields for the CurrentRecord, and assign them to the
fields for the TDBISAMTable using the TField.Assign method.

4) Call the TDBISAMTable.Post method.

You can see how to loop through the fields and assign one TField to another
here:

http://www.elevatesoft.com/dbisam_faqt_22.htm

--
Tim Young
Elevate Software
www.elevatesoft.com

Image