Hi Shesh, thanks for your quick answer.
The usage context is with our Genero runtime system (www.4js.com), using our Informix driver/interface, written in ESQL/C.
The code is quite complex and I would need some time to write a simplified ESQL/C sample.
However, I have tested different binding combinations (as we obviously support different SQL types like CHAR/VARCHAR/LVARCHAR and have different Genero BDL variable types CHAR/VARCHAR/STRING):
I confirm that when fetching an LVARCHAR into a C buffer (with fixed size memory allocated) and binding with sqlvar.sqltype = CVCHARTYPE or CCHARTYPE, the conversion is done as expected. This occurs when the target Genero/BDL variable is a CHAR(size) or VARCHAR(size) with a known size (memory is already allocated)
However, we have a proprietary STRING type in our language, with no theoretical max size. When fetching SQL CHAR or VARCHAR, we can get the max size from the descriptors (sqlvar.sqllen) and we can allocate the target buffer, but when the source SQL type is LVARCHAR, we use ifx_var_getdata() to get the string and then do a copy...
Summary:
If you confirm that binding with CLVCHARPTRTYPE does not do any charset conversion and that this is a feature rather than a bug, we would need another type id that does the conversion. However, this looks more like a bug.
Would a binding with CVCHARTYPE do the job? Assuming that there is no size limitation issue, since the SQL type VARCHAR() is limited to 255 bytes?
------------------------------
Sebastien FLAESCH
------------------------------
Original Message:
Sent: Wed February 10, 2021 07:31 AM
From: Sheshnarayan Agrawal
Subject: ESQL/C: Fetching LVARCHAR with ifx_var_getdata() when DB and client locale do not match
Hi Sebastien,
It appears that since bind type is pointer (CLVCHAR*PTR*TYPE), it doesn't go through possible conversion. Could you try with VARCHAR or any other suitable binding? Also, it would be good, if you could provide small testcase to understand the problem better.
Thanks
-Shesh
------------------------------
Sheshnarayan Agrawal
Original Message:
Sent: Tue February 09, 2021 08:59 AM
From: Sebastien FLAESCH
Subject: ESQL/C: Fetching LVARCHAR with ifx_var_getdata() when DB and client locale do not match
Hello!
Configuration:
Platforms: Linux Debian 10.7 or Windows 10
Informix server: IDS IDS-14.10.FC5
Informix client: CSDK 4.50.FC5
DB_LOCALE = en_us.utf8
CLIENT_LOCALE = en_us.8859-15 (Linux) / en_us.1252 (Windows)
We experience character encoding conversion issues when fetching an LVARCHAR column, when binding the fetch handler with ifx_sqlvar_t sqltype=CLVCHARPTRTYPE ...
Then we use the ifx_var_getdata() API to get the string value.
But it appears that the sequence of bytes returned by the ifx_var_getdata() function is pure UTF-8, and is not converted to ISO-8859-15 ... is this normal or a bug?
Note: When fetching a CHAR, VARCHAR or LVARCHAR column into an sqlvar C char[n] buffer that is allocated before the fetch, the UTF-8 characters are correctly converted to ISO-8859-15 ...
Can I find more details about charset conversions with ifx_var_getdata()?
Maybe we are missing something?
------------------------------
Sebastien FLAESCH
------------------------------
#Informix