Forum > Databases

[Solved] Zeos adding an extra #0 at the end of a UTF8 string

(1/2) > >>

Hi All,
Banging my head over this...
In my firebird 2.5 database all varchar fields are UTF-8.
The DB connection is UTF-8.
I use Zeos components in a console/server application in Free Pascal.
The ZConnection has all properties set to UTF-8.

At this application, a JSON arrives with a text containing UTF8 chars.
This should be posted into a FB table via a Zeos zquery that calls an SP.
The text arrives properly at the application, checked by writeln(atext);
Then I want to put it in the zQuery's parameter:

wrong result, garbage text where special characters are. But I thought all Free Pascal strings {$H+} are now UTF8?

Ok, next try:

params.parambyname('atext').asUnicodeString:=atext; Allmost good, it appears nicely in the table (checked by IBExpert) BUT it adds a chr(0) at the end.

I can't figure out where the #0 comes from...

What is ZEOS version ? I don't have such problems here.

OS?   On Windows UTF8 is only default for Lazarus GUI apps to my knowledge.

The extra #0 comes from the double #0#0 terminator in PWideChar... methinks...
Regards Benny


--- Quote from: JohnvdWaeter on February 13, 2024, 10:10:12 am ---But I thought all Free Pascal strings {$H+} are now UTF8?

--- End quote ---
That is only true for Lazarus applications. In FPC the stringtype is Ansi, not UTF8. (Is your app a console app?)
The extra zero comes from Widestring/PWideChar indeed.


[0] Message Index

[#] Next page

Go to full version