Get string as variant issue in non-utf8 databases
Original Reporter info from Mantis: zgabrovski
-
Reporter name: Zdravko Gabrovski
Original Reporter info from Mantis: zgabrovski
- Reporter name: Zdravko Gabrovski
Description:
Into a simple database application, which will create a LazReport over the non-utf8 firebird database (database character set = NONE, connection character set = WIN1251, new property UseConnectionCharSetIfNone=True), I discover, that LazReport display ????? instead of expected Cyrillic symbols.
After investigation of LazReport source code, I catch that LazReport extract data from the connection with the method
function lrGetFieldValue(F: TField): Variant;
in to lr_dbrel.pas source file, located into component/lazreport/source folder with a get-property call
Result:=F.Value;
located at line 123, where F is a TStringField.
So, this get property F.Value calls a function
function TStringField.GetAsVariant: variant;
located in fields.inc, line 1199.
Originally, function calls GetValue(s) method and assign a value directly to "result " variant, without calling setCodePage method, which will convert resulted variant into a right code page (1251 in my case).
Few lines above into fields.inc I found a method "GetAsString", which have a line "SetCodePage(RawByteString(Result), CP_ACP, True)", which is missing into "GetAsVariant" method.
So, I change the method "GetAsVarinat" to be:
function TStringField.GetAsVariant: variant;
var s : rawbytestring;
begin
If GetValue(s) then begin
SetCodePage(s, CP_ACP, True); // <<<<<<<<<<<<<<<<<<<<< Change <<<<
Result:=s;
end
else
Result:=Null;
end;
and now everything is OK and Lazreport display a report as I expect.
Steps to reproduce:
Discovered into description.
Additional information:
PLease, find attached screenshots before and after the fix.
Mantis conversion info:
- Mantis ID: 35796
- Build: trunk
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 42344 (#ebd005d1)
- Target version: 3.2.0