Board index » delphi » Master/Detail exception with AutoInc Field

Master/Detail exception with AutoInc Field

Hi,

I am using ADO to access a SQL server 7 database.
The master has a Counter field as primary key (CONT_ID).
The detail has a compound primary key : (CONT_ID + IDAD_ID)
The user must give me the value for IDAD_ID.

I made all the links between two TADODatasets.
The detail table is edited/display using a grid.
While testing the program under th Delphi IDE I get an exception.
If I try to insert a record "An Unknown error has occured"
If I moves through the columns, same error.
But when I post, the record is commited and fine. And
the master/detail relation is honored.

Outside the Delphi IDE (or turning off the exceptions) everything seems fine.

I dont know if I can deliver an application with such behaviour...
Is there anything I can do to avoid this? What am I missing?

Best regards,
Clment

 

Re:Master/Detail exception with AutoInc Field


I encountered the same problem.

I think the problem is that after the master table is posted, the auto inc
field value is not got by delphi/or ADO, in my case, the local copy of auto
inc field is always 0. And the local copy of the master record is different
with real record in db. Then, when a detail record should post, if you just
has a record with 0 CONT_ID, every thing will be OK except the detail record
is not in its right position, otherwise, it compliant that a record with
same foreign key should be exists.

I just close and reopen the master table and every thing will be right. I do
not know how to do it better.

Liwen.

Quote
Clment Doss <cd...@dhs.com.br> wrote in message

news:3A4BA20D.116D1897@dhs.com.br...
Quote
> Hi,

> I am using ADO to access a SQL server 7 database.
> The master has a Counter field as primary key (CONT_ID).
> The detail has a compound primary key : (CONT_ID + IDAD_ID)
> The user must give me the value for IDAD_ID.

> I made all the links between two TADODatasets.
> The detail table is edited/display using a grid.
> While testing the program under th Delphi IDE I get an exception.
> If I try to insert a record "An Unknown error has occured"
> If I moves through the columns, same error.
> But when I post, the record is commited and fine. And
> the master/detail relation is honored.

> Outside the Delphi IDE (or turning off the exceptions) everything seems
fine.

> I dont know if I can deliver an application with such behaviour...
> Is there anything I can do to avoid this? What am I missing?

> Best regards,
> Clment

Re:Master/Detail exception with AutoInc Field


Quote
>I am using ADO to access a SQL server 7 database.
>The master has a Counter field as primary key (CONT_ID).
>The detail has a compound primary key : (CONT_ID + IDAD_ID)
>The user must give me the value for IDAD_ID.

Have you set the Tfield AutoGenerate property?
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Maybe before you enter the detail grid, add the post method to the master
dataset will be OK.

The other reason maybe lie in the lookup field if you have in your detail
dataset.

Quote
"Qi Liwen" <qili...@21cn.com> wrote in message

news:92gsve$njf1@bornews.inprise.com...
Quote
> I encountered the same problem.

> I think the problem is that after the master table is posted, the auto inc
> field value is not got by delphi/or ADO, in my case, the local copy of
auto
> inc field is always 0. And the local copy of the master record is
different
> with real record in db. Then, when a detail record should post, if you
just
> has a record with 0 CONT_ID, every thing will be OK except the detail
record
> is not in its right position, otherwise, it compliant that a record with
> same foreign key should be exists.

> I just close and reopen the master table and every thing will be right. I
do
> not know how to do it better.

> Liwen.

> Clment Doss <cd...@dhs.com.br> wrote in message
> news:3A4BA20D.116D1897@dhs.com.br...
> > Hi,

> > I am using ADO to access a SQL server 7 database.
> > The master has a Counter field as primary key (CONT_ID).
> > The detail has a compound primary key : (CONT_ID + IDAD_ID)
> > The user must give me the value for IDAD_ID.

> > I made all the links between two TADODatasets.
> > The detail table is edited/display using a grid.
> > While testing the program under th Delphi IDE I get an exception.
> > If I try to insert a record "An Unknown error has occured"
> > If I moves through the columns, same error.
> > But when I post, the record is commited and fine. And
> > the master/detail relation is honored.

> > Outside the Delphi IDE (or turning off the exceptions) everything seems
> fine.

> > I dont know if I can deliver an application with such behaviour...
> > Is there anything I can do to avoid this? What am I missing?

> > Best regards,
> > Clment

Re:Master/Detail exception with AutoInc Field


Quote
> >I am using ADO to access a SQL server 7 database.
> >The master has a Counter field as primary key (CONT_ID).
> >The detail has a compound primary key : (CONT_ID + IDAD_ID)
> >The user must give me the value for IDAD_ID.
> Have you set the Tfield AutoGenerate property?

Yes to AutoInc (Master table CONT_ID field).

Re:Master/Detail exception with AutoInc Field


Quote
>Yes to AutoInc (Master table CONT_ID field).

Then are you sure the error is coming from the Autoinc field?
Are there any lookup fields in the table?  Lookup fields can cause the error you
described.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Yes there is a Lookup field.
But all work fine if I break the Master/Detail with autoinc field.
I will try to build a master/detail without the autoinc and see if
the problems still persists.
I appreciate you help
Quote
Brian Bushay TeamB wrote:
> >Yes to AutoInc (Master table CONT_ID field).

> Then are you sure the error is coming from the Autoinc field?
> Are there any lookup fields in the table?  Lookup fields can cause the error you
> described.

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


I'm getting the same error with lookup fields when the key field value (being used
for lookup) is NULL.  I DO NOT have any auto increment field, and I'm using Oracle.
Any explanations/suggestions (BTW - the BDE handled
the same code just fine.  It had other sever drawbacks, however... :-(  )
Avy
Quote
Brian Bushay TeamB wrote:
> >Yes to AutoInc (Master table CONT_ID field).

> Then are you sure the error is coming from the Autoinc field?
> Are there any lookup fields in the table?  Lookup fields can cause the error you
> described.

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Quote
>I'm getting the same error with lookup fields when the key field value (being used
>for lookup) is NULL.  I DO NOT have any auto increment field, and I'm using Oracle.
>Any explanations/suggestions

Set the lookup field lookupCache to true.  
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Thanks, it did it!
The only question is, why?  The documentation mentions that lookupCashe should be set to
true for performance reasons when the lookupset includes relatively small number of
records.  It does not say, by any means, that this is required.  Or that you will get an
'unknown error' exception, and only in design time.  (and, in my case, there are some
cases when the lookup set is pretty big - several hundred records).  Ids there any
explanation for this 'black magic'?

Thanks again
Avy

Quote
Brian Bushay TeamB wrote:
> >I'm getting the same error with lookup fields when the key field value (being used
> >for lookup) is NULL.  I DO NOT have any auto increment field, and I'm using Oracle.
> >Any explanations/suggestions

> Set the lookup field lookupCache to true.
> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Quote
>The only question is, why?  The documentation mentions that lookupCashe should be set to
>true for performance reasons when the lookupset includes relatively small number of
>records.  It does not say, by any means, that this is required.  Or that you will get an
>'unknown error' exception, and only in design time.  (and, in my case, there are some
>cases when the lookup set is pretty big - several hundred records).  Ids there any
>explanation for this 'black magic'?

I have not tried to figure out the source of this problem.  My opinion is that
if the lookup field values are  too large to cache you should not be using it.
Instead retrieve the value with your SQL command.  Lookup fields are Delphi
creations not native ADO when not cached they have a higher overhead then just
fetching the value in an SQL join

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


In general I agree, but lookup fields have the added benefit that the SQL remains live, since
it does not do a join, so the fields can be updated in a DBGrid.  If you take the SQL join
approach you win in performance, but lose in program complexity.
Avy
Quote
Brian Bushay TeamB wrote:
> >The only question is, why?  The documentation mentions that lookupCashe should be set to
> >true for performance reasons when the lookupset includes relatively small number of
> >records.  It does not say, by any means, that this is required.  Or that you will get an
> >'unknown error' exception, and only in design time.  (and, in my case, there are some
> >cases when the lookup set is pretty big - several hundred records).  Ids there any
> >explanation for this 'black magic'?

> I have not tried to figure out the source of this problem.  My opinion is that
> if the lookup field values are  too large to cache you should not be using it.
> Instead retrieve the value with your SQL command.  Lookup fields are Delphi
> creations not native ADO when not cached they have a higher overhead then just
> fetching the value in an SQL join

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Quote
>In general I agree, but lookup fields have the added benefit that the SQL remains live, since
>it does not do a join,

What database are you using?  ADO is designed for databases that return an
updateable Join.
MS SQL server and Access both give you updateable joins under ADO.
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


We are using Oracle
Avy
Quote
Brian Bushay TeamB wrote:
> >In general I agree, but lookup fields have the added benefit that the SQL remains live, since
> >it does not do a join,

> What database are you using?  ADO is designed for databases that return an
> updateable Join.
> MS SQL server and Access both give you updateable joins under ADO.
> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Master/Detail exception with AutoInc Field


Quote
>We are using Oracle

Ok I can't help you with oracle specific problems
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com
Go to page: [1] [2]

Other Threads