Page 1 of 1

zMemtableExt - helper class for zMemTable

Posted: 20.11.2021, 16:53
by kjteng
This is a helper class for zMemTable developed for my personal project. I have and made it (with demo program) available at https://github.com/kjteng/zMemTableExt

Methods implemented (using zstream.pas to compress the data)
procedure SaveToBlob(BField: TBlobField);
procedure LoadFromBlob(BField: TBlobField);
procedure SaveToFile(Filename: TFilename; zip: Boolean =True);
procedure LoadFromFile(Filename: TFilename);
procedure CopyStru(src: TDataSet; xcFields: TByteSet =[]; DeleteOldfields: Boolean=True);

I have only tested it on Lazarus ver2.0.12.
All are welcome to try it. Comments and suggestions would be highly appreciated.

Re: zMemtableExt - helper class for zMemTable

Posted: 20.11.2021, 19:02
by aehimself
Remarks:

[*] You don't need to "mark" zipped content. Just check if the ZLIB header is present in the first 2 bytes:

https://stackoverflow.com/questions/905 ... -look-like

[*] Use a TArray<Integer> for xcFields. FieldDefs is an Integer indexed property, your solution will work until only 255 fields.

[*] This kind of "protection" is also missing from LoadFromStream I think. In case a value can not be assigned to a field, dataset remains in dsInsert. To prevent this, in CopyData use the loading like this:

Code: Select all

Append;
Try
 [...]
Except
 On E:Exception Do
 Begin
   src.Cancel;
   Raise;
 End;
End;
Your idea of "LoadFromBlob" and "SaveToBlob" got me thinking. This actually can be used for nested datasets, like how FireDAC does it (there is a FieldType called ftDataSet after all).... maybe we can discuss it in a separate thread.
Kind of a big change as it would go back to TZAbstractRODataSet I think, so probably in 8.1 or later :)

Re: zMemtableExt - helper class for zMemTable

Posted: 21.11.2021, 08:25
by kjteng
Hi aehimself:
Thank you so much for your valuable feedback.
I have made the necessary changes based on your advice. I used array of integer instead of TArray<Integer> because I am not familiar with the use of generic type (and will study further on this subject).
Regards,
kjteng