Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit40cad8b

Browse files
committed
My first cut at libpq revision didn't handle MULTIBYTE correctly,
but I think it's OK now...
1 parentfad6f29 commit40cad8b

File tree

5 files changed

+53
-78
lines changed

5 files changed

+53
-78
lines changed

‎src/backend/access/common/printtup.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.43 1999/04/2503:19:23 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.44 1999/04/25 19:27:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,10 +25,6 @@
2525
#include"libpq/pqformat.h"
2626
#include"utils/syscache.h"
2727

28-
#ifdefMULTIBYTE
29-
#include"mb/pg_wchar.h"
30-
#endif
31-
3228
staticvoidprinttup_setup(DestReceiver*self,TupleDesctypeinfo);
3329
staticvoidprinttup(HeapTupletuple,TupleDesctypeinfo,DestReceiver*self);
3430
staticvoidprinttup_cleanup(DestReceiver*self);
@@ -157,14 +153,10 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver* self)
157153
StringInfoDatabuf;
158154
inti,
159155
j,
160-
k,
161-
outputlen;
156+
k;
162157
char*outputstr;
163158
Datumattr;
164159
boolisnull;
165-
#ifdefMULTIBYTE
166-
unsignedchar*p;
167-
#endif
168160

169161
/* Set or update my derived attribute info, if needed */
170162
if (myState->attrinfo!=typeinfo||
@@ -213,24 +205,13 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver* self)
213205
{
214206
outputstr= (char*) (*fmgr_faddr(&thisState->finfo))
215207
(attr,thisState->typelem,typeinfo->attrs[i]->atttypmod);
216-
#ifdefMULTIBYTE
217-
p=pg_server_to_client(outputstr,strlen(outputstr));
218-
outputlen=strlen(p);
219-
pq_sendint(&buf,outputlen+VARHDRSZ,VARHDRSZ);
220-
pq_sendbytes(&buf,p,outputlen);
221-
#else
222-
outputlen=strlen(outputstr);
223-
pq_sendint(&buf,outputlen+VARHDRSZ,VARHDRSZ);
224-
pq_sendbytes(&buf,outputstr,outputlen);
225-
#endif
208+
pq_sendcountedtext(&buf,outputstr,strlen(outputstr));
226209
pfree(outputstr);
227210
}
228211
else
229212
{
230213
outputstr="<unprintable>";
231-
outputlen=strlen(outputstr);
232-
pq_sendint(&buf,outputlen+VARHDRSZ,VARHDRSZ);
233-
pq_sendbytes(&buf,outputstr,outputlen);
214+
pq_sendcountedtext(&buf,outputstr,strlen(outputstr));
234215
}
235216
}
236217

‎src/backend/commands/async.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 1994, Regents of the University of California
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.45 1999/04/2503:19:08 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.46 1999/04/25 19:27:43 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -803,7 +803,7 @@ NotifyMyFrontEnd(char *relname, int32 listenerPID)
803803
pq_beginmessage(&buf);
804804
pq_sendbyte(&buf,'A');
805805
pq_sendint(&buf,listenerPID,sizeof(int32));
806-
pq_sendstring(&buf,relname,strlen(relname));
806+
pq_sendstring(&buf,relname);
807807
pq_endmessage(&buf);
808808
/* NOTE: we do not do pq_flush() here. For a self-notify, it will
809809
* happen at the end of the transaction, and for incoming notifies

‎src/backend/libpq/pqformat.c

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Copyright (c) 1994, Regents of the University of California
1717
*
18-
* $Id: pqformat.c,v 1.1 1999/04/2503:19:22 tgl Exp $
18+
* $Id: pqformat.c,v 1.2 1999/04/25 19:27:44 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -26,7 +26,7 @@
2626
*pq_sendbyte- append a raw byte to a StringInfo buffer
2727
*pq_sendint- append a binary integer to a StringInfo buffer
2828
*pq_sendbytes- append raw data to a StringInfo buffer
29-
*pq_sendtext- append a text string (with MULTIBYTE conversion)
29+
*pq_sendcountedtext- append a text string (with MULTIBYTE conversion)
3030
*pq_sendstring- append a null-terminated text string (with MULTIBYTE)
3131
*pq_endmessage- send the completed message to the frontend
3232
* Note: it is also possible to append data to the StringInfo buffer using
@@ -36,9 +36,8 @@
3636
* Message input:
3737
*pq_getint- get an integer from connection
3838
*pq_getstr- get a null terminated string from connection
39-
*pq_getnchar- get n characters from connection, and null-terminate
40-
* pq_getstr and pq_getnchar perform MULTIBYTE conversion on the collected
41-
* string. Use the raw pqcomm.c routines pq_getstring and pq_getbytes
39+
* pq_getstr performs MULTIBYTE conversion on the collected string.
40+
* Use the raw pqcomm.c routines pq_getstring or pq_getbytes
4241
* to fetch data without conversion.
4342
*/
4443
#include"postgres.h"
@@ -48,6 +47,7 @@
4847
#ifdefMULTIBYTE
4948
#include"mb/pg_wchar.h"
5049
#endif
50+
#include<string.h>
5151
#ifdefHAVE_ENDIAN_H
5252
#include<endian.h>
5353
#endif
@@ -110,36 +110,49 @@ pq_sendbytes(StringInfo buf, const char *data, int datalen)
110110
}
111111

112112
/* --------------------------------
113-
*pq_sendtext- append a text string (with MULTIBYTE conversion)
113+
*pq_sendcountedtext- append a text string (with MULTIBYTE conversion)
114114
*
115-
*NB: passed text string must be null-terminated, even though we expect
116-
* thecaller to hand us the length (this is just becausethecaller
117-
*usually knows the length anyway). In this routine,the data sent to
118-
* the frontendis NOT null-terminated.
115+
*The data sent to the frontend by this routine is a 4-byte count field
116+
*(thecount includes itself, by convention) followed bythestring.
117+
*The passed text string need not be null-terminated, andthe data sent
118+
*tothe frontendisn't either.
119119
* --------------------------------
120120
*/
121121
void
122-
pq_sendtext(StringInfobuf,constchar*str,intslen)
122+
pq_sendcountedtext(StringInfobuf,constchar*str,intslen)
123123
{
124124
#ifdefMULTIBYTE
125-
str= (constchar*)pg_server_to_client(str,slen);
125+
constchar*p;
126+
p= (constchar*)pg_server_to_client((unsignedchar*)str,slen);
127+
if (p!=str)/* actual conversion has been done? */
128+
{
129+
str=p;
130+
slen=strlen(str);
131+
}
126132
#endif
133+
pq_sendint(buf,slen+4,4);
127134
appendBinaryStringInfo(buf,str,slen);
128135
}
129136

130137
/* --------------------------------
131138
*pq_sendstring- append a null-terminated text string (with MULTIBYTE)
132139
*
133-
* NB: passed text string must be null-terminated, even though we expect
134-
* the caller to hand us the length (this is just because the caller
135-
* usually knows the length anyway).
140+
* NB: passed text string must be null-terminated, and so is the data
141+
* sent to the frontend.
136142
* --------------------------------
137143
*/
138144
void
139-
pq_sendstring(StringInfobuf,constchar*str,intslen)
145+
pq_sendstring(StringInfobuf,constchar*str)
140146
{
147+
intslen=strlen(str);
141148
#ifdefMULTIBYTE
142-
str= (constchar*)pg_server_to_client(str,slen);
149+
constchar*p;
150+
p= (constchar*)pg_server_to_client((unsignedchar*)str,slen);
151+
if (p!=str)/* actual conversion has been done? */
152+
{
153+
str=p;
154+
slen=strlen(str);
155+
}
143156
#endif
144157
appendBinaryStringInfo(buf,str,slen+1);
145158
}
@@ -258,35 +271,18 @@ pq_getstr(char *s, int maxlen)
258271
c=pq_getstring(s,maxlen);
259272

260273
#ifdefMULTIBYTE
261-
p= (char*)pg_client_to_server((unsignedchar*)s,maxlen);
262-
if (s!=p)/* actual conversion has been done? */
263-
strcpy(s,p);
264-
#endif
265-
266-
returnc;
267-
}
268-
269-
/* --------------------------------
270-
*pq_getnchar - get n characters from connection, and null-terminate
271-
*
272-
*returns 0 if OK, EOF if trouble
273-
* --------------------------------
274-
*/
275-
int
276-
pq_getnchar(char*s,intlen)
277-
{
278-
intc;
279-
#ifdefMULTIBYTE
280-
char*p;
281-
#endif
282-
283-
c=pq_getbytes(s,len);
284-
s[len]='\0';
285-
286-
#ifdefMULTIBYTE
287-
p= (char*)pg_client_to_server((unsignedchar*)s,len+1);
288-
if (s!=p)/* actual conversion has been done? */
289-
strcpy(s,p);
274+
p= (char*)pg_client_to_server((unsignedchar*)s,strlen(s));
275+
if (p!=s)/* actual conversion has been done? */
276+
{
277+
intnewlen=strlen(p);
278+
if (newlen<maxlen)
279+
strcpy(s,p);
280+
else
281+
{
282+
strncpy(s,p,maxlen);
283+
s[maxlen-1]='\0';
284+
}
285+
}
290286
#endif
291287

292288
returnc;

‎src/backend/tcop/dest.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.26 1999/04/2503:19:09 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.27 1999/04/25 19:27:45 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -155,8 +155,7 @@ BeginCommand(char *pname,
155155

156156
for (i=0;i<natts;++i)
157157
{
158-
pq_sendstring(&buf,attrs[i]->attname.data,
159-
strlen(attrs[i]->attname.data));
158+
pq_sendstring(&buf,attrs[i]->attname.data);
160159
pq_sendint(&buf, (int)attrs[i]->atttypid,
161160
sizeof(attrs[i]->atttypid));
162161
pq_sendint(&buf,attrs[i]->attlen,

‎src/include/libpq/pqformat.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pqformat.h,v 1.1 1999/04/2503:19:14 tgl Exp $
8+
* $Id: pqformat.h,v 1.2 1999/04/25 19:27:47 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -19,13 +19,12 @@
1919

2020
externvoidpq_sendbyte(StringInfobuf,intbyt);
2121
externvoidpq_sendbytes(StringInfobuf,constchar*data,intdatalen);
22-
externvoidpq_sendtext(StringInfobuf,constchar*str,intslen);
23-
externvoidpq_sendstring(StringInfobuf,constchar*str,intslen);
22+
externvoidpq_sendcountedtext(StringInfobuf,constchar*str,intslen);
23+
externvoidpq_sendstring(StringInfobuf,constchar*str);
2424
externvoidpq_sendint(StringInfobuf,inti,intb);
2525
externvoidpq_endmessage(StringInfobuf);
2626

2727
externintpq_getint(int*result,intb);
2828
externintpq_getstr(char*s,intmaxlen);
29-
externintpq_getnchar(char*s,intlen);
3029

3130
#endif/* PQFORMAT_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp