Re: Problem retrieving data

From: Kouame Narcisse Koffi <koffinarcisseservice(at)gmail(dot)com>
To: rob stone <floriparob(at)tpg(dot)com(dot)au>, Igor Korot <ikorot01(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Problem retrieving data
Date: 2026-11-15 12:34:46
Message-ID: MA4P292MB0423A9176327E93E31314095A87D2@MA4P292MB0423.ESPP292.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-odbc

Hi Igor,

This doesn't look like a driver problem, and I don't think you need to forward it to the PG-ODBC list. The truncation comes from the BufferLength argument you pass to SQLBindCol.

BufferLength is expressed in BYTES, not in characters. SQLWCHAR is 2 bytes on your platform, so a value of 33 gives the driver room for 16 SQLWCHARs: 15 characters plus the terminating null. That is exactly what you see: "BenefitsCheckBo" is 15 characters, followed by the 0 in your gdb dump. Your cbStyleName = 32 is the driver telling you it had 32 bytes (16 characters) of data available, which is more than your buffer could hold. The driver most likely returned SQL_SUCCESS_WITH_INFO (SQLSTATE 01004, string data, right truncated), and your loop accepts that code silently.

Suggested fixes:

1. Pass the real buffer size in bytes:
SQLBindCol( m_hstmt, 1, SQL_C_WCHAR, styleName, sizeof( styleName ), &cbStyleName );
and likewise sizeof( styleStyle ) and sizeof( work ). Right now styleStyle[255] is also bound with 33 bytes, although abe_edit can hold 254 characters. Also make sure the arrays are large enough for the column length + 1 (abe_name is varchar(30), so 31 SQLWCHARs is the minimum).

2. Match the C types to the column types. abe_flag is an integer with values like 536870916 and -201326590, but you bind it as SQL_C_USHORT, which keeps only the low 16 bits. Use SQL_C_SLONG with a SQLINTEGER. For the smallint columns, use SQL_C_SSHORT with SQLSMALLINT (or SQL_C_SLONG with an int). Binding SQL_C_USHORT to an int variable only works by accident on little-endian machines.

3. Check the indicators for SQL_NULL_DATA before using the buffers. abe_work (and abe_edit) can be NULL, as in the first BenefitsCheckBox row.

4. Log the return value of SQLFetch when it is SQL_SUCCESS_WITH_INFO, and call SQLGetDiagRec to read the diagnostics. It would have shown the truncation immediately.

Minor point: in your query buffer, memset( qry.get(), '\0', query.length() + 2 ) clears bytes, not SQLWCHARs, so it should be ( query.length() + 2 ) * sizeof( SQLWCHAR ). It doesn't matter if uc_to_str_cpy terminates the string, but it's worth fixing.

Hope this helps.

Envoyé à partir de Outlook pour Android<https://aka.ms/AAb9ysg>
________________________________
From: rob stone <floriparob(at)tpg(dot)com(dot)au>
Sent: Sunday, 15 November 2026 12:25:58
To: Igor Korot <ikorot01(at)gmail(dot)com>; pgsql-generallists.postgresql.org <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Problem retrieving data

On Sun, 2026-11-15 at 01:11 -0600, Igor Korot wrote:
>

$9 = 0x65 <error: Cannot access memory at address 0x65>

Maybe this ought to be rectified?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nick Gorham 2026-11-15 13:19:51 Re: Fwd: Problem retrieving data
Previous Message rob stone 2026-11-15 12:25:58 Re: Problem retrieving data

Browse pgsql-odbc by date

  From Date Subject
Next Message Nick Gorham 2026-11-15 13:19:51 Re: Fwd: Problem retrieving data
Previous Message rob stone 2026-11-15 12:25:58 Re: Problem retrieving data