EDatabaseError with message Field 'xxxxxx' must have a value

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
napi
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.03.2007, 02:30

EDatabaseError with message Field 'xxxxxx' must have a value

Post by napi »

hi buddy,

I was install Zeos 6.6.1 beta to replace 6.1.5 version in my application. How ever, i get an error above when inserting new record.

FYI, i'm using firebird database with generator and trigger. It seem trigger does'nt work in version 6.6.1.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Hi,

You will have to set the 'required' poperty on the field to 'false'. I suppose the field is required in the database (primary key, probably?), so ZEOS defaults it to required as it isn't aware of what your triggers do before inserting. As I understood from other posts on this forum you can override that, however.

Mark
napi
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.03.2007, 02:30

Post by napi »

Hi,

That field is primary key and default set to 'not null' in firebird. How ever your solution is work when i remove primary key parameter.

Is there any solution which don't require to remove primary key.?
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Napi,

Can you identify this kind of 'autoincrement' fields in Firebird. Is it easy to see that a generator is used for a certain field? I think current implementation always sets the FAutoincrement swith to false for all fields.
For mysql we can easyly find out a field is an autoincrement field and in this case it is allowed to be null, even when the field is defined as 'Not Null'.
When I remove this workaround for mysql and test then the program requires a value indeed.
Thus, after the 'open' in my testcase I added 'ZQuery1.FieldByName('c_id').Required := false;' That made it all work again. So you can work around it if you know there is a generator on your primary key.
Mark
napi
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.03.2007, 02:30

Post by napi »

hi mdaems

below is my table structure

Code: Select all

/* table structure */

CREATE TABLE "SIMPAN" 
(
  "ID_SIMPAN"	INTEGER NOT NULL,
  "ID_MS"	VARCHAR(10) CHARACTER SET WIN1251,
  "NAMA"	VARCHAR(100),
 PRIMARY KEY ("ID_SIMPAN")
);



/* Triggers  */

CREATE TRIGGER "BI_SIMPAN_ID_SIMPAN" FOR "SIMPAN" 
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.ID_SIMPAN IS NULL) THEN
      NEW.ID_SIMPAN = GEN_ID(SIMPAN_ID_SIMPAN_GEN, 1);
END
 ^

/*generator */
CREATE GENERATOR SIMPAN_ID_SIMPAN_GEN;
In firebird, i cannot set primary key to NULL
bangfauzan
Senior Boarder
Senior Boarder
Posts: 50
Joined: 31.08.2006, 10:41
Contact:

Post by bangfauzan »

Hi napi

What mdeam says is corret, you don't have to make any modification in your DDL (Data Definition Language) like removing the primary key. Do not do anything over the DDL. Also you dont have to remove anything on your Dataset. You Just have change the "Required" property to False on the Field handled by GENERATOR.

FYI:
Primary key can not be set to NULL, that is the rule of overall database system.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Hi Bangfauzan, Napi,

Is a generator linked to a specific field and can this be retrieved from the information tables provided by Firebird? That way we can try to implement the autoincrement exeption we also used for mysql. Any idea?

@napi, I hope you now understand what I meant and your problem is solved now?

Mark
napi
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.03.2007, 02:30

Post by napi »

hi bangfauzan, mdaems

Yes, i understand now. I follow your example and it's work. Just set required to False.

exp

Code: Select all

tblQuestion.FieldByName('ID_SIMPAN').Required := false;
tblQuestion.append;
tblQuestion.FieldByName('ID_MS').asInteger := 1;
tblQuestion.FieldByName('NAMA').asString :='Test';
tblQuestion.post;
there are other solution that i was tested using sequence;

Code: Select all

ZSequence1.SequenceName := 'SIMPAN_ID_SIMPAN_GEN';
tblQuestion.append;
tblQuestion.FieldByName('ID_SOALAN').AsInteger := ZSequence1.GetNextValue;
tblQuestion.FieldByName('ID_MS').asInteger := 1;
tblQuestion.FieldByName('NAMA').asString :='Test';
tblQuestion.post;
Thanks Buddy.
Post Reply