fcl-db: fix an issue with FieldDefs Code Page and String Field DataSize in TBufDataSet
Original Reporter info from Mantis: zgabrovski
-
Reporter name: Zdravko Gabrovski
Original Reporter info from Mantis: zgabrovski
- Reporter name: Zdravko Gabrovski
Description:
In a TBufdataset for a backward compatibility, the datasize of FieldDef for string data type becomes = of FieldDef Size property, which comes (probably) for a compatibility with old code.
It works prefect for all non-unicode characters, which have character size = 1.
But if you want to use UTF8 Unicode characters (for example Cyrillic letters) it will not work OK.
After some digging, I found that the problem comes from TFiedDef creation , which creates FieldDef always with CP_ANSI encoding. In this case, GetDataSize method always returns DataSize=Size, which breaks UTF8 Unicode characters.
I did the following patch:
in db.pas - little modification, that allow to modify code page of particular TFieldDef (just add write property handler of public CodePage property).
in bufdataset.pas :
- Create a new Public procedure "SetCodePage" with parameter new code page; The procedure sets a new code page to all String FieldDefs in TBufDataSet;
- Create a new event Handler "OnCreateDataSet" which is reached before Field from FieldDef creation, a perfect place to setup a new code page of the TDufdataset.
Everything is designed for keep of backward compatibility for a current TBufDataSet implementation.
Mantis conversion info:
- Mantis ID: 38181
- OS: all
- OS Build: all
- Build: fcldb - trunk
- Platform: all
- Version: 3.3.1