views:

228

answers:

1

I use Delphi 7 + Zeos + MySQL, and I got a problem when I try to post Master table, the Details datasets are posted first, raising a referencial integrity exception in data base, 'couse details tables needs the ID of the Master table.

Can I revert this behavior? Can I persist the master table before the details?

+1  A: 

I think it's just the way TDataSet work. If you have unposted detail records, master.Post forces them to Post if I remember correctly.

So I am guessing you have something like:

tblMaster.Insert;
tblMaster.FieldByName('foo').Value := 'foo';
tblDetail.Insert;
tblDetail.FieldByName('bar').Value := 'bar';
tblMaster.Post; // error!
tblDetail.Post;

You should be able to work around this by posting master first:

tblMaster.Insert;
tblMaster.FieldByName('foo').Value := 'foo';
tblMaster.Post;
tblDetail.Insert;
tblDetail.FieldByName('bar').Value := 'bar';
tblDetail.Post;
eed3si9n
eed3si9n, thanks for your answer, sure it's one way to get job done, but it's not applyable in this specific case, in the truth, I'm using this methodology as a crutch, but it don't solves the real problem as I'll show you: I got a form that performs interface to two difents tables, a base table and a complementary table with more detailed fields. For the users, it's only one thing, they have to press only one "save" button.
Gedean Dias
I'm trying to skip it with a palliativing way, while I haven't the kill solution: I made a component that, when a insert occurs in the master table, it disables the detail table and cache the input data in a memory based dataset and when after post master, it enables the detail and copy the memory cached data into the persistent dataset. Works fine with two tables, I'm trying to enhance it to use with more than only two tables.
Gedean Dias