Page 1 of 1

EDatabaseError with message Field 'xxxxxx' must have a value

Posted: 05.03.2007, 02:41
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.

Posted: 05.03.2007, 08:40
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

Posted: 08.03.2007, 07:38
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.?

Posted: 08.03.2007, 23:01
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

Posted: 12.03.2007, 01:34
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

Posted: 12.03.2007, 04:36
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.

Posted: 13.03.2007, 00:14
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

Posted: 13.03.2007, 05:05
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.