questionable codes in libpq/backend communication

Started by Nonameover 27 years ago2 messages
#1Noname
t-ishii@sra.co.jp

Hi, There are some codes in libpq/backend communication that seem very
strange to me.

in backend/access/common/printtup.c printtup():

pq_putint(strlen(outputstr) + VARHDRSZ, VARHDRSZ);
pq_putnchar(outputstr, strlen(outputstr));

the first line above sends the data length and second actually sends
the data. My question is why the data length is "strlen(outputstr) +
VARHDRSZ", not just strlen(outputstr). After some investigation, I
found a code fragment that might be an answer. In
interfaces/libpq/fe-exec.c getTuple():

/* get the value length (the first four bytes are for length) */
pqGetInt(&vlen, 4, pfin, pfdebug);
if (binary == 0)
{
vlen = vlen - 4;
}

Woh! The misterious 4-byte has been subtracted by libpq! Seems they
have been remained just for historical reasons.
--
Tatsuo Ishii
t-ishii@sra.co.jp

#2Andreas Zeugswetter
andreas.zeugswetter@telecom.at
In reply to: Noname (#1)
AW: [HACKERS] questionable codes in libpq/backend communication

My question is why the data length is "strlen(outputstr) +
VARHDRSZ", not just strlen(outputstr).

I also think that this is a little annoying, but there seems to be no
easy way out, since all user code has a reference to VARHDRSZ.
Therefore all existing code would need to be ported. Since I don't
have lots of C code I would vote for doing this, but what would
those with lots of code say :( ?

Andreas

PS: Maybe some good macros for users would be good to hide VARHDRSZ