# DASchema and businessprocessor that fails to throw an exception

**URL:** https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614
**Category:** Data Abstract
**Tags:** delphi
**Created:** [August 12, 2024, 3:43pm UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614 "2024-08-12T15:43:40Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![marcantheunis](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@marcantheunis](https://talk.remobjects.com/u/marcantheunis)
#### Post date: [August 12, 2024, 3:43pm UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/1 "2024-08-12T15:43:41Z")

</div>

hi,  
i had a nasty problem where a DA schema table ‘lost’ the primary key property of a field (i guess as a result of an update to the fields cause i added some fields in the query)  
that said, the server side business processor was in a updWhereKeyOnly mode (auto generated update stats)  
so since this is a rather difficult situation to auto generate update statements whithout knowing the field of the primary key i would expect the business processor throwing an exception saying just that…  
now it falls back to creating a where clause using all fields that are updated so a bit like upWhereAll…  
resulting in the most weird and unpredictable update statements…

so i’de really like to see an exception implemented that fires when a businessprocessor is defined as updWhereKeyOnly and the referenced dataset has no primary key defined…

would have saved me a lot of time finding the problem and fixing databases…

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 12, 2024, 3:50pm UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/2 "2024-08-12T15:50:48Z")

</div>

Hi,

What version of DAD are you using?  
If you are using SQL mode and custom SQL are used, it is as designed.  
DAD can’t detect PK from user’s SQL because it can be select from view or some similar case. For SQL mode you should set PK manually.

try to drop query component to form and execute `select * from table` - PK information will be missed…

---

<div class="post-metadata">

### Author: ![marcantheunis](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@marcantheunis](https://talk.remobjects.com/u/marcantheunis)
#### Post date: [August 12, 2024, 3:54pm UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/3 "2024-08-12T15:54:15Z")

</div>

SDAC  
the problem isn’t that custom sql is used - i get that i need to define the PK myselves…  
the problem is that the business process is configured to generate its statements based in updWhereKEYonly…  
so imho if there is no field defined as primary key it should throw an exception cause it just can’t generate any statement that is to be trusted to correctly update the desired record…

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 12, 2024, 6:13pm UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/4 "2024-08-12T18:13:53Z")

</div>

Hi,

you can change it to any other value:

```auto
 TDAUpdateMode = (updWhereKeyOnly, updWhereAll, updWhereKeyAndUserDefined, updWhereUserDefined);

```

for autogenerated BP you can set it in [DataService.OnBusinessProcessorAutoCreated](https://docs.dataabstract.com/API/Delphi/Classes/TDataAbstractService/#OnBusinessProcessorAutoCreated) event or just drop TDABusinessProcessor to your DataAbstract service and setup it for your table …

---

<div class="post-metadata">

### Author: ![marcantheunis](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@marcantheunis](https://talk.remobjects.com/u/marcantheunis)
#### Post date: [August 12, 2024, 6:22pm UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/5 "2024-08-12T18:22:14Z")

</div>

hi Evgeny,

- i have a businessprocessor on the datamodule for the schema
- the businessprocessor is set to updWhereKEYonly
- the businessprocessor referenced datatable is MISSING the primary key field info

since the businessprocessor is setup correctly and since the schema table not since it is missing the primary key field info, it should throw an exception since it can’t proceed updating without knowing the primary key field name…

i don’t see how you last reply is an answer to the problem honestly…  
it’s not about changing the update mode, it’s about not honoring the update mode that was set on the business processor  
imho this should throw an exception  
and frankly i was expection none the less…  
it is a safeguard for problems that can and will arise in the schema if one uses custom sql…

so the real question is why it does not throw an exception and if so, can this behaviour can be changed in a future release (or be configured to throw an exception)  
it’s the only way of having some kind of runtime check to see if the primkey field is defined…

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 13, 2024, 6:55am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/6 "2024-08-13T06:55:09Z")

</div>

Hi,

> [@marcantheunis](#):
>
> since the businessprocessor is setup correctly and since the schema table not since it is missing the primary key field info, it should throw an exception since it can’t proceed updating without knowing the primary key field name…

we use this logic:

```auto
if (aDelta.KeyFieldCount = 0) and (lUpdateMode = updWhereKeyOnly) then lUpdateMode := updWhereAll;

```

You can check for PK and set own value …

---

<div class="post-metadata">

### Author: ![marcantheunis](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@marcantheunis](https://talk.remobjects.com/u/marcantheunis)
#### Post date: [August 13, 2024, 7:03am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/7 "2024-08-13T07:03:31Z")

</div>

i don’t want to check for PK…  
what is the point of auto generate statements in a business processor when you define updWhereKEYonly when there is no PK field present in the schema table?  
i should be a safeguard…  
hence the logic :  
if (aDelta.KeyFieldCount = 0) and (lUpdateMode = updWhereKeyOnly) then lUpdateMode := updWhereAll;  
should not exists imho and instead throw an exception  
cause this alters the way the auto generated statements _are intended to be generated_

i don’t like that behaviour defined in a component using a property of that component changes like the intended behaviour…

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 13, 2024, 7:09am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/8 "2024-08-13T07:09:51Z")

</div>

Hi,

this logic is present since beginning for 20+ years.

if you dislike this behavior, you can check for `aDelta.KeyFieldCount = 0` and raise exception in events like [TDataAbstractService.OnBeforeProcessDeltas](https://docs.dataabstract.com/API/Delphi/Classes/TDataAbstractService/#OnBeforeProcessDeltas) or [TDABusinessProcessor.OnBeforeProcessDelta](https://docs.dataabstract.com/API/Delphi/Classes/TDABusinessProcessor/#OnBeforeProcessDelta)

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [August 13, 2024, 11:09am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/9 "2024-08-13T11:09:38Z")

</div>

> [@EvgenyK](#):
>
> this logic is present since beginning for 20+ years.
> 
> if you dislike this behavior, you can check for `aDelta.KeyFieldCount = 0` and raise exception in events like [TDataAbstractService.OnBeforeProcessDeltas](https://docs.dataabstract.com/API/Delphi/Classes/TDataAbstractService/#OnBeforeProcessDeltas) or [TDABusinessProcessor.OnBeforeProcessDelta](https://docs.dataabstract.com/API/Delphi/Classes/TDABusinessProcessor/#OnBeforeProcessDelta)

I agree with Marc here. updWhereKeyOnly should fail, if there IS no primary key set, because thats clearly an unexpected error condition, and cannot work.

—marc

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [August 13, 2024, 11:31am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/10 "2024-08-13T11:31:17Z")

</div>

Logged as [bugs://D19481](https://www.remobjects.com/portal/bugs/?id=D19481).

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [August 15, 2024, 7:10am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/11 "2024-08-15T07:10:03Z")

</div>

[bugs://D19481](https://www.remobjects.com/portal/bugs/?id=D19481) was closed as fixed.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [August 15, 2024, 7:16am UTC](https://talk.remobjects.com/t/daschema-and-businessprocessor-that-fails-to-throw-an-exception/30614/12 "2024-08-15T07:16:29Z")

</div>

Hi,

- update `uDABusinessProcessor.pas` as

old line:

```delphi
if (aDelta.KeyFieldCount = 0) and (lUpdateMode = updWhereKeyOnly) then lUpdateMode := updWhereAll;

```

new line:

```delphi
DAError((aDelta.KeyFieldCount = 0) and (lUpdateMode = updWhereKeyOnly), 'updWhereKeyOnly mode is incompatible with delta that has no primary keys');

```

- close Delphi IDE
- launch `C:\Program Files (x86)\RemObjects Software\Build\install_DA.cmd` with admin rights
