PQfnumber() Fix Proposal

Started by Volkan YAZICIabout 20 years ago2 messages
#1Volkan YAZICI
volkan.yazici@gmail.com

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.)
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"(*).
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.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Volkan YAZICI (#1)
Re: PQfnumber() Fix Proposal

Volkan YAZICI <volkan.yazici@gmail.com> writes:

Here's my proposal without breaking the current implementation:
[18: ] name + '\0' + lowercased_name

Forget it --- this is proposing a protocol breakage in order to deal
with libpq's internal mistake. It does not address the problem either;
which string is PQfnumber supposed to compare to?

regards, tom lane