*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.43 1999/04/25 03:19:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.44 1999/04/25 19:27:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "libpq/pqformat.h"
#include "utils/syscache.h"
-#ifdef MULTIBYTE
-#include "mb/pg_wchar.h"
-#endif
-
static void printtup_setup(DestReceiver* self, TupleDesc typeinfo);
static void printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver* self);
static void printtup_cleanup(DestReceiver* self);
StringInfoData buf;
int i,
j,
- k,
- outputlen;
+ k;
char *outputstr;
Datum attr;
bool isnull;
-#ifdef MULTIBYTE
- unsigned char *p;
-#endif
/* Set or update my derived attribute info, if needed */
if (myState->attrinfo != typeinfo ||
{
outputstr = (char *) (*fmgr_faddr(&thisState->finfo))
(attr, thisState->typelem, typeinfo->attrs[i]->atttypmod);
-#ifdef MULTIBYTE
- p = pg_server_to_client(outputstr, strlen(outputstr));
- outputlen = strlen(p);
- pq_sendint(&buf, outputlen + VARHDRSZ, VARHDRSZ);
- pq_sendbytes(&buf, p, outputlen);
-#else
- outputlen = strlen(outputstr);
- pq_sendint(&buf, outputlen + VARHDRSZ, VARHDRSZ);
- pq_sendbytes(&buf, outputstr, outputlen);
-#endif
+ pq_sendcountedtext(&buf, outputstr, strlen(outputstr));
pfree(outputstr);
}
else
{
outputstr = "<unprintable>";
- outputlen = strlen(outputstr);
- pq_sendint(&buf, outputlen + VARHDRSZ, VARHDRSZ);
- pq_sendbytes(&buf, outputstr, outputlen);
+ pq_sendcountedtext(&buf, outputstr, strlen(outputstr));
}
}
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqformat.c,v 1.1 1999/04/25 03:19:22 tgl Exp $
+ * $Id: pqformat.c,v 1.2 1999/04/25 19:27:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* pq_sendbyte - append a raw byte to a StringInfo buffer
* pq_sendint - append a binary integer to a StringInfo buffer
* pq_sendbytes - append raw data to a StringInfo buffer
- * pq_sendtext - append a text string (with MULTIBYTE conversion)
+ * pq_sendcountedtext - append a text string (with MULTIBYTE conversion)
* pq_sendstring - append a null-terminated text string (with MULTIBYTE)
* pq_endmessage - send the completed message to the frontend
* Note: it is also possible to append data to the StringInfo buffer using
* Message input:
* pq_getint - get an integer from connection
* pq_getstr - get a null terminated string from connection
- * pq_getnchar - get n characters from connection, and null-terminate
- * pq_getstr and pq_getnchar perform MULTIBYTE conversion on the collected
- * string. Use the raw pqcomm.c routines pq_getstring and pq_getbytes
+ * pq_getstr performs MULTIBYTE conversion on the collected string.
+ * Use the raw pqcomm.c routines pq_getstring or pq_getbytes
* to fetch data without conversion.
*/
#include "postgres.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#endif
+#include <string.h>
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
}
/* --------------------------------
- * pq_sendtext - append a text string (with MULTIBYTE conversion)
+ * pq_sendcountedtext - append a text string (with MULTIBYTE conversion)
*
- * NB: passed text string must be null-terminated, even though we expect
- * the caller to hand us the length (this is just because the caller
- * usually knows the length anyway). In this routine, the data sent to
- * the frontend is NOT null-terminated.
+ * The data sent to the frontend by this routine is a 4-byte count field
+ * (the count includes itself, by convention) followed by the string.
+ * The passed text string need not be null-terminated, and the data sent
+ * to the frontend isn't either.
* --------------------------------
*/
void
-pq_sendtext(StringInfo buf, const char *str, int slen)
+pq_sendcountedtext(StringInfo buf, const char *str, int slen)
{
#ifdef MULTIBYTE
- str = (const char *) pg_server_to_client(str, slen);
+ const char *p;
+ p = (const char *) pg_server_to_client((unsigned char *) str, slen);
+ if (p != str) /* actual conversion has been done? */
+ {
+ str = p;
+ slen = strlen(str);
+ }
#endif
+ pq_sendint(buf, slen + 4, 4);
appendBinaryStringInfo(buf, str, slen);
}
/* --------------------------------
* pq_sendstring - append a null-terminated text string (with MULTIBYTE)
*
- * NB: passed text string must be null-terminated, even though we expect
- * the caller to hand us the length (this is just because the caller
- * usually knows the length anyway).
+ * NB: passed text string must be null-terminated, and so is the data
+ * sent to the frontend.
* --------------------------------
*/
void
-pq_sendstring(StringInfo buf, const char *str, int slen)
+pq_sendstring(StringInfo buf, const char *str)
{
+ int slen = strlen(str);
#ifdef MULTIBYTE
- str = (const char *) pg_server_to_client(str, slen);
+ const char *p;
+ p = (const char *) pg_server_to_client((unsigned char *) str, slen);
+ if (p != str) /* actual conversion has been done? */
+ {
+ str = p;
+ slen = strlen(str);
+ }
#endif
appendBinaryStringInfo(buf, str, slen+1);
}
c = pq_getstring(s, maxlen);
#ifdef MULTIBYTE
- p = (char*) pg_client_to_server((unsigned char *) s, maxlen);
- if (s != p) /* actual conversion has been done? */
- strcpy(s, p);
-#endif
-
- return c;
-}
-
-/* --------------------------------
- * pq_getnchar - get n characters from connection, and null-terminate
- *
- * returns 0 if OK, EOF if trouble
- * --------------------------------
- */
-int
-pq_getnchar(char *s, int len)
-{
- int c;
-#ifdef MULTIBYTE
- char *p;
-#endif
-
- c = pq_getbytes(s, len);
- s[len] = '\0';
-
-#ifdef MULTIBYTE
- p = (char*) pg_client_to_server((unsigned char *) s, len+1);
- if (s != p) /* actual conversion has been done? */
- strcpy(s, p);
+ p = (char*) pg_client_to_server((unsigned char *) s, strlen(s));
+ if (p != s) /* actual conversion has been done? */
+ {
+ int newlen = strlen(p);
+ if (newlen < maxlen)
+ strcpy(s, p);
+ else
+ {
+ strncpy(s, p, maxlen);
+ s[maxlen-1] = '\0';
+ }
+ }
#endif
return c;
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqformat.h,v 1.1 1999/04/25 03:19:14 tgl Exp $
+ * $Id: pqformat.h,v 1.2 1999/04/25 19:27:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern void pq_sendbyte(StringInfo buf, int byt);
extern void pq_sendbytes(StringInfo buf, const char *data, int datalen);
-extern void pq_sendtext(StringInfo buf, const char *str, int slen);
-extern void pq_sendstring(StringInfo buf, const char *str, int slen);
+extern void pq_sendcountedtext(StringInfo buf, const char *str, int slen);
+extern void pq_sendstring(StringInfo buf, const char *str);
extern void pq_sendint(StringInfo buf, int i, int b);
extern void pq_endmessage(StringInfo buf);
extern int pq_getint(int *result, int b);
extern int pq_getstr(char *s, int maxlen);
-extern int pq_getnchar(char *s, int len);
#endif /* PQFORMAT_H */