Required is true for calculate field?

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

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
User avatar
dhongu
Junior Boarder
Junior Boarder
Posts: 37
Joined: 28.09.2005, 08:37
Location: Bucuresti
Contact:

Required is true for calculate field?

Post by dhongu »

I have mysql table
[syntax="sql"]
CREATE TABLE `tabel1` (
`ID` int(11) NOT NULL auto_increment,
`Val` int(11) default NULL,
`Description` varchar(20) default NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM;
[/syntax]

and code:
[syntax="delphi"]
procedure TForm1.Button1Click(Sender: TObject);
var MyZQuery:TZQuery;
begin
MyZQuery:=TZQuery.Create(self);
MyZQuery.Connection:=ZConnection1;
MyZQuery.SQL.Text:='select *, id+1 as Calc from tabel1';
MyZQuery.Open;
MyZQuery.Insert;
MyZQuery.FieldByName('Val').Value:='1000';
MyZQuery.FieldByName('Description').Value:='Description 1000';
MyZQuery.Post;
MyZQuery.Close;
MyZQuery.Free;
end;
[/syntax]

If you try to post on new record without set field `calc` program raised exception class EDatabaseError with message 'Field 'Calc' must have a value'.

For simple sql with calculate field is necessary to define ZUpdateObject :(.
It is possible to set Request = false for calculate field ?
Dorin Hongu
User avatar
dhongu
Junior Boarder
Junior Boarder
Posts: 37
Joined: 28.09.2005, 08:37
Location: Bucuresti
Contact:

Post by dhongu »

?
Dorin Hongu
btrewern
Expert Boarder
Expert Boarder
Posts: 193
Joined: 06.10.2005, 18:51

Post by btrewern »

Try setting

Code: Select all

MyZQuery.FieldByName('Calc').Required := False;
Not tested but should work.

Regards,

Ben
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 Dorin,

I just added a small test to avoid that fields which are not writable are set required.
For me it seems to work right.
Real reason for the error : mysql returns these fields as not null (field flags in C api) Apparently it derives this from the fact that the id column is not null and it's just an addition. If your calculation would have been more difficult like 'if(id<10,null,id) as calc' the api returns 'null allowed' and the required property is not set.

Committed in SVN testing branch REV 226.

Mark
Post Reply