BUG #11767: ODBC driver bug when fetching constant string columns

From: keyurgovande(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #11767: ODBC driver bug when fetching constant string columns
Date: 2014-10-22 21:22:10
Message-ID: 20141022212210.2665.47909@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-odbc

The following bug has been logged on the website:

Bug reference: 11767
Logged by: Keyur Govande
Email address: keyurgovande(at)gmail(dot)com
PostgreSQL version: 9.0.3
Operating system: Centos 6.5
Description:

Hello,

This was reported to the PHP project (https://bugs.php.net/bug.php?id=68087)
but it seems like a Postgres ODBC driver bug.

If we run a SELECT statement like: SELECT id, varchar_col, date_col, 'random
string' as random;
via ODBC, then the last column comes back as junk into PHP.

In PHP we use the SQL_DESC_OCTET_LENGTH to figure out how many bytes to
allocate. But for that column, SQL_DESC_OCTET_LENGTH returns 0 and we don't
allocate enough space.

The driver issue seems to be that when SQLColAttributes() is called with
SQL_COLUMN_TYPE for column 'random', it returns SQL_VARCHAR even though the
PG type is PG_TYPE_UNKNOWN. The promotion is happening here:
http://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=pgtypes.c;h=4ce7636b69d371d9f511d492c68013f070e3b32a;hb=HEAD#l665

I think the same promotion needs to happen when fetching octet-length here:
http://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=pgtypes.c;h=4ce7636b69d371d9f511d492c68013f070e3b32a;hb=HEAD#l1275

Thoughts? This is not a problem when using the Vertica ODBC driver for
example.

A temporary workaround is to use a cast thusly: SELECT id, varchar_col,
date_col, varchar 'random string' as random;

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2014-10-22 22:16:01 Re: BUG #11712: Empty string as error message from libpq
Previous Message olegjobs 2014-10-22 17:27:03 BUG #11761: range_in dosn't work via direct functional call

Browse pgsql-odbc by date

  From Date Subject
Next Message Michael Paquier 2014-10-24 13:36:31 Re: [BUGS] BUG #11767: ODBC driver bug when fetching constant string columns
Previous Message Michael Paquier 2014-10-20 12:06:24 Re: This may be a bug: odbc's function"check_client_encoding" have the same name with postgres's function.