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 ?
Required is true for calculate field?
Moderators: gto, cipto_kh, EgonHugeist
Required is true for calculate field?
Dorin Hongu
Try setting Not tested but should work.
Regards,
Ben
Code: Select all
MyZQuery.FieldByName('Calc').Required := False;
Regards,
Ben
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
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
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