#1 2011-09-12 08:55:18

corchi72
Member
Registered: 2010-12-10
Posts: 232

How to use ManyDelete and BatchDelete together

I wanted to replace

1)ADatabase.Delete (TSQLField, FIDS [i]); 

with

2)ADatabase.BatchDelete (FIDS [i]);

but I have not figured out how do I delete table relationships TSQLField with TSQLQvw?  (AQvw.Fields)

I have to do a cycle and delete one  at a time?

if ADatabase.TransactionBegin(TSQLField) then
begin
 ADatabase.BatchStart(TSQLField);
          for I := 0 to Length(fIds) - 1 do
          begin
              if not (Progress.fCancel) then
              begin
       
//              ADatabase.Delete(TSQLField,fIds[i]);
              ADatabase.BatchDelete(fIds[i]);
              AQvw.Fields.ManyDelete(ADatabase, AQvw.ID, fIds[i]);
              Progress.Position := i;

              end
              else
               begin
                 
                 ADatabase.BatchAbort;
                 ADatabase.RollBack;
                 exit;
               end;
          end;

          ADatabase.BatchSend(Results);
          ADatabase.Commit;
end;

Thanks corchi

Offline

#2 2011-09-16 07:03:40

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to use ManyDelete and BatchDelete together

please help? how to use manydelete in a batch

Offline

#3 2011-09-16 09:24:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: How to use ManyDelete and BatchDelete together

There is no batch version of the ManyDelete method (yet).

You'll have to call ManyDelete multiple times, but you should not mix it with BatchDelete/BatchSend commands, because batch deletions are performed only on BatchSend.

Offline

#4 2011-09-16 11:56:56

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to use ManyDelete and BatchDelete together

I imagined it, but i have one table and more relations and anywhere i delete the record i must to remeber to delete all relations connected to the record.

You know a better way to delete a record and all relationships without having to cycle all the records one by one?

thanks

Offline

#5 2011-09-21 07:42:54

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to use ManyDelete and BatchDelete together

There is a "procedure/function" that erases all the relationships are no longer valid?
How to delete a record in one table and automatically to delete  all the relationships of same record?

Thanks corchi

Offline

#6 2012-08-19 10:15:58

mvddoes
Member
Registered: 2012-08-11
Posts: 6

Re: How to use ManyDelete and BatchDelete together

Hello,

I am also curious to the answer on the question above.

in code below, a cascaded delete as defined in the database does not work...

      bRC:=Database.Delete(TSQLPatients, iID);

While when deleting the record in a database tool, the cascaded delete works fine... how come?

Regards,
Maurijn

Offline

#7 2012-08-20 07:49:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: How to use ManyDelete and BatchDelete together

I've added an aUseBatchMode optional parameter to TSQLRecordMany.ManyDelete() method.
See http://synopse.info/fossil/info/c0c4838f26

It may help you calling ManyDelete() within a BATCH sequence.

Thanks for the feedback.

Offline

Board footer

Powered by FluxBB