RE: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count? - Mailing list pgsql-odbc

From Wal, Jan Tjalling van der
Subject RE: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?
Date
Msg-id AM0PR01MB5634012E7A37C8D806933665DD0D9@AM0PR01MB5634.eurprd01.prod.exchangelabs.com
Whole thread Raw
In response to SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?  (Marsupilami79 <marsupilami79@gmx.de>)
Responses Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?
List pgsql-odbc
Hello Marsupilami79, Jan,

It could be that the answers you receive are in fact correct for postgres.
In a database set to charset=UTF-8 I get the following answers.

select  'topsales' as string, char_length('topsales'), length('topsales'), octet_length('topsales');
"string"        "char_length"    "length"    "octet_length"
"topsales"    8        8        8

However for a variation that requires more bytes to store the answer start to differ.
select  'töpsålés'as string, char_length('töpsålés'), length('töpsålés'), octet_length('töpsålés');
"string"        "char_length"    "length"    "octet_length"
"töpsålés"    8        8        11

In the above octet_length is a postgres-function that yields results in bytes. 
And the three characters with a diacritical added, each requires 2 bytes, yielding a resulting lengt of 11 instead of
8.
 

Kind regards, Jan Tjalling van der Wal


-----Original Message-----
From: Marsupilami79 <marsupilami79@gmx.de> 
Sent: 22 November 2022 16:57
To: pgsql-odbc@lists.postgresql.org
Subject: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?

Hello,

I am a co author of a data access library and we recently added an ODBC bridge. This bridge has the capability to
deteminethe current Catalog / Database. This is done by calling SQLGetConnectAttrW.
 

We try to determine the size of the buffer that is needed for the catalog name in the following manner:
SQLGetConnectAttrW(fHDBC, SQL_ATTR_CURRENT_CATALOG, null, 0, &aLen)

The ODBC driver for Microsoft SQL server correctly returns the number of bytes required (10 bytes for the Database name
"Stork")in the aLen parameter. The ODBC driver for PostgreSQL returns the number of characters (8 characters for a
databasenamed "topsales"), where it should return 16 for the number of bytes required.
 

I tested this with the psqlodbc_13_02_0000-x86 download for Windows 10 and installed the Unicode ODBC driver.

I assume this is a bug and needs to be fixed. I just don't know if this is the right place to report the bug to?

With best regards,

Jan



pgsql-odbc by date:

Previous
From: Marsupilami79
Date:
Subject: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?
Next
From: Jon Raiford
Date:
Subject: Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?