Page 1 of 1

ZMemTable ignoring required fields

Posted: 27.05.2022, 21:39
by aehimself
It's not an inconvenience at all but at least easy to reproduce. Have a ZMemTable, a datasource and a DBGrid connected on your blank app, and write the following code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
 ZMemTable1.FieldDefs.Add('ID', ftLargeInt, 0, True);
 ZMemTable1.FieldDefs.Add('Text', ftWideString, 100, True);

 ZMemTable1.Open;

 ZMemTable1.Append;
 ZMemTable1.FieldByName('ID').AsLargeInt := ZMemTable1.RecordCount + 1;
 ZMemTable1.Post;
end;
In theory, this shouldn't be possible, post should throw an exception but instead, one record is visible in the grid.

I used a ZMemTable to display a data structure in a heavily customized DBGrid, so it really doesn't matter for me. However, this should be looked at in the future. A quick debug in .Post reveals absolutely zero checks on required fields whatsoever; maybe because TZVirtualResultSet.PostRowUpdates is empty. I admit I was a bit lazy to check where the exception is raised with TZQuery.

Using D11.1 patch 1 but I suspect a check is missing in Zeos's code so it shouldn't matter.

Re: ZMemTable ignoring required fields

Posted: 29.05.2022, 10:46
by marsupilami
Hello aehimself,

I created a bug report for this on the bug tracker: https://sourceforge.net/p/zeoslib/tickets/550/

Currently I am out of time becaus emy job requires all my free time. This bug report makes sure, it is not forgotten.

Best regards,

Jan

Re: ZMemTable ignoring required fields

Posted: 26.10.2022, 10:34
by aehimself
Fixed :)

Pull request available on GitHub.

Re: ZMemTable ignoring required fields

Posted: 26.10.2022, 11:44
by aehimself
Does anyone know what this means by the way? This is why inherited isn't called, this is why required fields are simply ignored.

//AVZ - Firebird defaults come through when this is commented out

Maybe it worth a try to simply call inherited and run it against the tests. I would like that solution better than the overridden method - but again, only if it's not causing issues with FireBird.

Re: ZMemTable ignoring required fields

Posted: 27.10.2022, 09:01
by marsupilami
aehimself wrote: 26.10.2022, 11:44 Does anyone know what this means by the way? This is why inherited isn't called, this is why required fields are simply ignored.

//AVZ - Firebird defaults come through when this is commented out

Maybe it worth a try to simply call inherited and run it against the tests. I would like that solution better than the overridden method - but again, only if it's not causing issues with FireBird.
We will do exactly that. I will fire up the test server today after lunch. Then I will make the necessary changes in Zeos 8.0. If these changes fix the problem, we probably transfer that solution to trunk.

Thank you for your work :)

Re: ZMemTable ignoring required fields

Posted: 27.10.2022, 09:25
by aehimself
I saw that Michael took a different approach fixing this, the commit is already in SubVersion. However I don't see the reason for a required check to be implemented 3 different locations (once in TDataSet, once in TZAbstractRODataset and now in TZMemTableResultSet) this solution feels a lot more elegant than mine :)

Just make sure that these won't interfere with each other.

Re: ZMemTable ignoring required fields

Posted: 19.11.2022, 11:20
by hemmingway
Hello,

now I must disable required check on one table (TZTable).
The required fields on a MariaDB server are filled, but the check raises an exception.

Greeings, Bernhard

Re: ZMemTable ignoring required fields

Posted: 19.11.2022, 20:42
by aehimself
Can you check the metadata, if NULLABLE is properly returned and detected by Zeos?
Also, a minimal example would be appreciated so we can check what is going wrong.