Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread best method to achieve this (save 'all or nothing')
Mon, Nov 10 2008 11:44 AMPermanent Link

=?iso-8859-1?Q?Santy_Concepci=F3n?=
Hi!

Our application saves data in two different tables (one master table and one
detail table).
We first save the first record in the master table, and then, the detail
records in the second table.

Some few customers have encountered problems when trying to save the detail
records on the second table, so the master table contains data, but the
second table is empty.

We need to cancel or delete the master record if the detailed records were
not saved in second table, or better, ensure the saving of the data in both
tables.

Do you know any method to ensure the data saving in this situation? Maybe
posting the detailed records first, or using transactions, etc...?

Thanks

Santy C.
Mon, Nov 10 2008 12:54 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Santy,

<< Some few customers have encountered problems when trying to save the
detail records on the second table, so the master table contains data, but
the second table is empty. >>

Could you post the code that you're using ?

Thanks,

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Nov 10 2008 1:14 PMPermanent Link

"Robert"

"Santy Concepción" <santyweb@hotmail.com> wrote in message
news:BA80D72A-6C4E-4192-B548-9CBA50284083@news.elevatesoft.com...
> Hi!
>
> Our application saves data in two different tables (one master table and
> one detail table).
> We first save the first record in the master table, and then, the detail
> records in the second table.
>
> Some few customers have encountered problems when trying to save the
> detail records on the second table, so the master table contains data, but
> the second table is empty.
>
> We need to cancel or delete the master record if the detailed records were
> not saved in second table, or better, ensure the saving of the data in
> both tables.
>

If the saving of the master and detail all occur at the same time, then a
transaction is the obvious best solution (in pseudocode)

database.starttransaction
try
save details
save master
database commit
except database rollback

if they occur at different times - that is, you have already saved the
master when you're ready to save the details

database.starttransaction
try
save details
database commit
except
 database rollback
 delete the master
end

Robert


Mon, Nov 10 2008 1:22 PMPermanent Link

=?iso-8859-1?Q?Santy_Concepci=F3n?=
Hi, Tim...

The code is simple, but very large (lot of fields)
It is something like this:

//First Table:

           follow := true;

           table1.append;
           table1.fieldbyname('DATE').Asstring := Datetostr(date);
           table1.fieldbyname('TIME').Asdatetime := now;
           table1.fieldbyname('NUMBER').AsString := label5.caption;
           {.....}
           try
               table1.post;
               table1.flushbuffers;
               follow := true;
           except
               on E:Exception do
               begin
                   follow:=false;
                   showmessage('Error ocurred...'+
                        #13#13#10+E.message);
               end;
           end;

//Second Table:

           if follow then   //if firts table was saved correctly
           begin
                   table3.first;
                   while not(table3.eof) do
                   begin
                       table2.append;
                       table2.fieldbyname('DATE').Asstring :=
Datetostr(date);
                       table2.fieldbyname('TIME').Asdatetime := now;
                       table2.fieldbyname('NUMBER').AsString :=
label5.caption;
                       {......}
                       table2.post;

                       table3.next;
                   end;
           end
           else
               showmessage('table1 not saved, so table2 is not saved');

The problem is that, sometimes table1 is saved, but table2 is not saved at
all.
I have improved it a little bit and now it will show detailed messages when
error occurs.

Thanks!


--
Santy C

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> escribió en el
mensaje de
noticias:50425529-5CE3-4DBC-86AC-1F09A32AF2F8@news.elevatesoft.com...
> Santy,
>
> << Some few customers have encountered problems when trying to save the
> detail records on the second table, so the master table contains data, but
> the second table is empty. >>
>
> Could you post the code that you're using ?
>
> Thanks,
>
> --
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
Tue, Nov 11 2008 2:22 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Santy,

<< The problem is that, sometimes table1 is saved, but table2 is not saved
at all. >>

You're not cancelling the Append when there's an error during the Post.  You
need something like this:

            try
               table1.post;
               table1.flushbuffers;
               follow := true;
           except
               on E:Exception do
               begin
                   if (Table1.State=dsInsert) then
                      Table1.Cancel;
                   follow:=false;
                   showmessage('Error ocurred...'+
                        #13#13#10+E.message);
               end;
           end;

Leaving around a record buffer in dsInsert mode can result in another
implicit Post call when the user navigates the Table1 component in any way.

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Nov 11 2008 2:24 PMPermanent Link

"Walter Matte"
Are you doing anything in the BeforePost or AfterPost or other event to
reposition the Table1 and therby not get Table2 associated....

What Exception are you getting?  what is the "Detailed Message" you are now
getting?

Walter

"Santy Concepción" <santyweb@hotmail.com> wrote in message
news:748AB7C7-BB7E-4C60-8E90-1FD81C43AA18@news.elevatesoft.com...
> Hi, Tim...
>
> The code is simple, but very large (lot of fields)
> It is something like this:
>
> //First Table:
>
>            follow := true;
>
>            table1.append;
>            table1.fieldbyname('DATE').Asstring := Datetostr(date);
>            table1.fieldbyname('TIME').Asdatetime := now;
>            table1.fieldbyname('NUMBER').AsString := label5.caption;
>            {.....}
>            try
>                table1.post;
>                table1.flushbuffers;
>                follow := true;
>            except
>                on E:Exception do
>                begin
>                    follow:=false;
>                    showmessage('Error ocurred...'+
>                         #13#13#10+E.message);
>                end;
>            end;
>
> //Second Table:
>
>            if follow then   //if firts table was saved correctly
>            begin
>                    table3.first;
>                    while not(table3.eof) do
>                    begin
>                        table2.append;
>                        table2.fieldbyname('DATE').Asstring :=
> Datetostr(date);
>                        table2.fieldbyname('TIME').Asdatetime := now;
>                        table2.fieldbyname('NUMBER').AsString :=
> label5.caption;
>                        {......}
>                        table2.post;
>
>                        table3.next;
>                    end;
>            end
>            else
>                showmessage('table1 not saved, so table2 is not saved');
>
> The problem is that, sometimes table1 is saved, but table2 is not saved at
> all.
> I have improved it a little bit and now it will show detailed messages
> when error occurs.
>
> Thanks!
>
>
> --
> Santy C
>
> "Tim Young [Elevate Software]" <timyoung@elevatesoft.com> escribió en el
> mensaje de
> noticias:50425529-5CE3-4DBC-86AC-1F09A32AF2F8@news.elevatesoft.com...
>> Santy,
>>
>> << Some few customers have encountered problems when trying to save the
>> detail records on the second table, so the master table contains data,
>> but the second table is empty. >>
>>
>> Could you post the code that you're using ?
>>
>> Thanks,
>>
>> --
>> Tim Young
>> Elevate Software
>> www.elevatesoft.com
>>

Wed, Nov 12 2008 10:18 AMPermanent Link

=?iso-8859-1?Q?Luis_Concepci=F3n?=
Thanks, Walter...

I added the 'detailed message' option a few days ago. Now I have to send the
patch to some customers to see what happens.
I'm pretty sure it is not software related, because the code is very simple.
Maybe corrupted files, hard disk, network, etc...

I will try your tips in the following days.

Thanks!

"Walter Matte" <mattew_@_interlog.com> escribió en el mensaje de
noticias:28BA5D8B-08CC-4A18-9060-246513B77C5A@news.elevatesoft.com...
> Are you doing anything in the BeforePost or AfterPost or other event to
> reposition the Table1 and therby not get Table2 associated....
>
> What Exception are you getting?  what is the "Detailed Message" you are
> now getting?
>
> Walter
>
> "Santy Concepción" <santyweb@hotmail.com> wrote in message
> news:748AB7C7-BB7E-4C60-8E90-1FD81C43AA18@news.elevatesoft.com...
>> Hi, Tim...
>>
>> The code is simple, but very large (lot of fields)
>> It is something like this:
>>
>> //First Table:
>>
>>            follow := true;
>>
>>            table1.append;
>>            table1.fieldbyname('DATE').Asstring := Datetostr(date);
>>            table1.fieldbyname('TIME').Asdatetime := now;
>>            table1.fieldbyname('NUMBER').AsString := label5.caption;
>>            {.....}
>>            try
>>                table1.post;
>>                table1.flushbuffers;
>>                follow := true;
>>            except
>>                on E:Exception do
>>                begin
>>                    follow:=false;
>>                    showmessage('Error ocurred...'+
>>                         #13#13#10+E.message);
>>                end;
>>            end;
>>
>> //Second Table:
>>
>>            if follow then   //if firts table was saved correctly
>>            begin
>>                    table3.first;
>>                    while not(table3.eof) do
>>                    begin
>>                        table2.append;
>>                        table2.fieldbyname('DATE').Asstring :=
>> Datetostr(date);
>>                        table2.fieldbyname('TIME').Asdatetime := now;
>>                        table2.fieldbyname('NUMBER').AsString :=
>> label5.caption;
>>                        {......}
>>                        table2.post;
>>
>>                        table3.next;
>>                    end;
>>            end
>>            else
>>                showmessage('table1 not saved, so table2 is not saved');
>>
>> The problem is that, sometimes table1 is saved, but table2 is not saved
>> at all.
>> I have improved it a little bit and now it will show detailed messages
>> when error occurs.
>>
>> Thanks!
>>
>>
>> --
>> Santy C
>>
>> "Tim Young [Elevate Software]" <timyoung@elevatesoft.com> escribió en el
>> mensaje de
>> noticias:50425529-5CE3-4DBC-86AC-1F09A32AF2F8@news.elevatesoft.com...
>>> Santy,
>>>
>>> << Some few customers have encountered problems when trying to save the
>>> detail records on the second table, so the master table contains data,
>>> but the second table is empty. >>
>>>
>>> Could you post the code that you're using ?
>>>
>>> Thanks,
>>>
>>> --
>>> Tim Young
>>> Elevate Software
>>> www.elevatesoft.com
>>>
>
>
Image