1

My Firebird field (ID) functions like an autoinc field (it has a generator and a trigger for the occasion). When I use Firebird Maestro and do some manual inserts the autoinc field functions ok (I just need to refresh the table). However, on Delphi side (using FireDac) is another issue. Soon as I try and do an insert I get a warning message "Field 'ID' must have a value". What is going on? Any way to correct this?

Edit: As you can see in the picture, the field gets added but table stays in insert mode and displays an error!

enter image description here

Edit2: I have turned off the requirement for ID to have the value but still the error persists (I have turned the connection on and off just in case so it does not stay in memory)

enter image description here

user3927897
  • 611
  • 3
  • 10
  • 20
  • 1
    Is ID accessed by a persistent TField component which is configured with the flag "required"? – mjn Sep 16 '14 at 14:46
  • The only field in the database that has "notNull" is the ID field. All others are not required. – user3927897 Sep 16 '14 at 14:53
  • "that has "notNull" is the ID field" But is it defined in the DB to be a PK or to require a UNIQUE value? FireDAC is normally excellent at determining the correct behaviour, provided the db metadata tells it what it needs to know. It doesn't sound, from the limited amount you say, that it does. – MartynA Sep 16 '14 at 22:31
  • Autoinc generated numbers are always unique. The generator always increases by one. Strange thing is that I see in the grid the ID field fill in correctly. However, after it gets filled I get the error that the field ID must have a value and the table remains in edit mode. In Firebird Maestro, doing inserts from there, has autoinc field functioning properly. So nothing wrong with the field.However, to see the newly generated field number I must refresh the table. From what I could understand, same thing happens with Firedac. Field is inserted but firedac does not see it. – user3927897 Sep 17 '14 at 05:09
  • To see the inserted number, I must refresh the table but Firedac cant refresh unless data is actually posted. And it is not because ID number is missing. And thats a loop over here. how to cut this loop, I dont know....In SQLite, everything functions fine. – user3927897 Sep 17 '14 at 05:11

3 Answers3

2

When you create a connection and config a table to Fetch your data, Delphi recognize all not null field and automatically set Required property = true.

Required  = true

Look, not null field or autoincrement serial must be required, except when you set some default value in database. In this case the user can keep the field blank, and the database assume the default value as well, before post.

To solve this just set Required = false in object inspector for the field ID.

Note: You changed the field property NOT REQUIRED in database, however the field property is required = true in Delphi since you start dragging table in form. Table and fdTable components are not sensible to modification in database. To examine the behavior I describe below, drop new table or do delete all field and add all field again for your table

1

Set -1 to ID. The TField required property is probably true in your case.

oPsDCadarn
  • 106
  • 3
1

If there is a persistent TField in the dataset fields which has the required option set, the Post will not succeed unless a value is assigned. In this situation it is not the database which rejects the insert, but the data access framework.

So check the dataset component in your datamodule if it uses persistent fields, and if it does, check the field options.

Maybe you can also post the relevant DFM code in your question. Without complete information, it is hard to answer your question.

mjn
  • 36,362
  • 28
  • 176
  • 378