Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?

Поиск
Список
Период
Сортировка
От Marsupilami79
Тема Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?
Дата
Msg-id acca9004-ac38-fedb-8564-ea13edb5eb8c@gmx.de
обсуждение исходный текст
Ответ на RE: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?  ("Wal, Jan Tjalling van der" <jan_tjalling.vanderwal@wur.nl>)
Ответы Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?
Список pgsql-odbc
Hello Jan Tjalling, hello Jon,

Jon is right - SQLGetConnectAttrW is a WideChar function (2 Bytes per Character). So the encoding in the PG database should not matter. It should return the length for the SQL_ATTR_CURRENT_CATALOG attribute in bytes. So for a database named "topsales" it should return 16 because each character uses two bytes.

I assume this is a bug in the PostgreSQL ODBC driver. The question is where to file a bug report and how to get this fixed? Is there a chance to get this fixed?

With best regards,

Jan Baumgarten

Am 25.11.2022 um 20:22 schrieb Wal, Jan Tjalling van der:
@font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; font-size:11.0pt; font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;}span.EmailStyle19 {mso-style-type:personal-reply; font-family:"Verdana",sans-serif; color:#1F497D;}.MsoChpDefault {mso-style-type:export-only; font-size:10.0pt;}div.WordSection1 {page:WordSection1;}

Okay, getting out of my comfort zone here.

I have found encoding options for PostgreSQL (v15) here:

PostgreSQL: Documentation: 15: 24.3. Character Set Support; they do not include UTF16, just UTF8.

There is no mention of UTF16 anywhere on that page.

 

I also found this: PostgreSQL: Re: DataDirect Driver, ExecDirect and UTF-8 that does mention WCHAR being different form CHAR and how that could work.

 

I hope there is something on these pages that helps you further.

 

Kind regards, Jan Tjalling

 

From: Jon Raiford <raiford@labware.com>
Sent: 25 November 2022 03:58
To: Wal, Jan Tjalling van der <jan_tjalling.vanderwal@wur.nl>; Marsupilami79 <marsupilami79@gmx.de>; pgsql-odbc@lists.postgresql.org
Subject: Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?

 

I believe the point is that the function is a "W" (wide char 16-bit) function so the strings should be UTF-16.

 

Jon


From: Wal, Jan Tjalling van der <jan_tjalling.vanderwal@wur.nl>
Sent: Tuesday, November 22, 2022 11:21:56 AM
To: Marsupilami79 <marsupilami79@gmx.de>; pgsql-odbc@lists.postgresql.org <pgsql-odbc@lists.postgresql.org>
Subject: RE: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?

 

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 detemine the 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 database named "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 по дате отправления:

Предыдущее
От: "Wal, Jan Tjalling van der"
Дата:
Сообщение: RE: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?
Следующее
От: Jon Raiford
Дата:
Сообщение: Re: SQLGetConnectAttrW + SQL_ATTR_CURRENT_CATALOG => wrong byte count?