Question

I have the following DBX structure in my software:

TSQLDataSet -> TDataSetProvider -> TClientDataSet

One of the fields from my TClientDataSet has the property Required set to false, because this field auto increments based on triggers and generators on the database (Firebird).

However, after configuring both TSQLDataSet and TClientDataSet with this field not being required, I'm getting really weird results when I try to read this field from my TClientDataSet. I suspect that I might need to do something extra to force my TClientDataSet to acquire the value of this field in this condition.

What am I missing here?

Thanks in advance.

EDIT

The help file for the Required property says something about this, but I couldn't quite understand what it want me to do.

Description

Specifies whether a nonblank value for a field is required.

Use Required to find out if a field requires a value or if the field can be blank.

If a field is created with the Fields editor, this property is set based on the underlying table. Applications that set Required to true for fields that must have values (for example, a password or part number), but for which the underlying table does not require the field, must write an OnValidate event handler to enforce the property.

When the Required property reflects a property of the underlying database table, trying to post apply a null value causes an exception to be raised. Applications that set the Required property to true when the underlying table does not require the field, should raise an EDatabaseError exception on null values in the OnValidate event handler in order to achieve the same result.

EDIT 2

Forgot to mention: between the TDataSetProvider and the TClientDataSet, there is a DataSnap layer (the TClientDataSet connection is made with a DataSnap driver).

EDIT 3

I created a small test case with this DataSnap setup and it worked perfectly. The project is legacy, messy and I guess that either I have an obscure option configured somewhere that is biting me or I have stumbled in a DataSnap bug.

Was it helpful?

Solution 2

Seems that the problem was an outdated field being read as an INTEGER and it was a SMALLINT in the database.

This problem was hard to debug and this question was misleading. Thanks for everyone that helped me debug this.

OTHER TIPS

Haole, have you tried TClientDataset.RefreshRecord after inserting? Or even TClientDataset.Refresh? Having generators, you can even get the generator in advance (before calling ApplyUpdates) in a query like select gen_id(generator,1) from RDB$Database (it's from memory, don't have Firebird here to test) and fill the PK field in advance.

EDIT: seems this is a heisenbug. I would try to remove the components and reconfigure them again from scratch (which means: after you remove, save and close Delphi).

Or even better, create an empty project with just that needed query configuration and try to view that data in a TDBGrid. If this problem still happens, maybe your FB installation have some component corrupted (or even Delphi installation)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top