PQfnumber() Fix Proposal

From: Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PQfnumber() Fix Proposal
Date: 2005-11-27 12:02:51
Message-ID: 7104a7370511270402o2a5cb266r4c4444822f353593@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Related TODO paragraph:
«Prevent PQfnumber() from lowercasing unquoted the column name.
PQfnumber() should never have been doing lowercasing, but historically
it has so we need a way to prevent it.»

PQfnumber() Fix Proposal
------------------------
In the current version of PQfnumber(), if user doesn't put quotes around
requested column name, libpq tries to lowercase both requested column name
and actual column names, then compares each of them one by one. Here's the
deal:

[1] If user put quotes around requested column name, no lowercasing will be
made in the libpq while comparing column names. (Current behaviour for
quoted column names.)

[2] If user doesn't use any quotes, API will assume the requested column name
is lowercased. After that, it will compare the given input with the
"lowercased column names"(*).

(*) How can we transmit column names lowercased in the server side without
causing any compatibility problems?

When we look at the fe-protocol3.c, getRowDescriptions() splits data
(conn->workBuffer) in this way:

Offset: 0 4 6 10 12 16 18
+----+--+----+--+----+--+--------------+
| | | | | | | |
+----+--+----+--+----+--+--------------+

[ 0: 3] tableid
[ 4: 5] columnid
[ 6: 9] typid
[10:11] typlen
[12:15] atttypmod
[16:17] format
[18: ] name

Here's my proposal without breaking the current implementation:

[18: ] name + '\0' + lowercased_name

("'\0' + lowercased_name" part will be added in the server side while building
column descriptions.)

Current functions in libpq, compares given column names using
strcmp(attDescs[i].name, input) call. So new implementation won't casue any
compatibility issues. But new getRowDescriptions() function will be aware of the
hidden "lowercased column name" in the retrieved column description data and
escape it to another variable in attDescs as (for instance) lowername.
Therefore, PQfnumber() can use attDescs[i].lowername while making
case insensitive compare.

Waiting for your comments.
Regards.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2005-11-27 13:24:35 Re: Windows installation notes
Previous Message Christopher Kings-Lynne 2005-11-27 09:59:09 Re: gprof SELECT COUNT(*) results