Index: doc/src/sgml/datatype.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/datatype.sgml,v
retrieving revision 1.131
diff -c -r1.131 datatype.sgml
*** doc/src/sgml/datatype.sgml 16 Nov 2003 20:29:16 -0000 1.131
--- doc/src/sgml/datatype.sgml 29 Nov 2003 05:28:38 -0000
***************
*** 1076,1084 ****
strings are distinguished from characters strings by two
characteristics: First, binary strings specifically allow storing
octets of value zero and other non-printable
! octets. Second, operations on binary strings process the actual
! bytes, whereas the encoding and processing of character strings
! depends on locale settings.
--- 1076,1085 ----
strings are distinguished from characters strings by two
characteristics: First, binary strings specifically allow storing
octets of value zero and other non-printable
! octets (defined as octets outside the range 32 to 126).
! Second, operations on binary strings process the actual bytes,
! whereas the encoding and processing of character strings depends
! on locale settings.
***************
*** 1131,1144 ****
\\
! Note that the result in each of the examples in was exactly one
! octet in length, even though the output representation of the zero
! octet and backslash are more than one character.
--- 1132,1156 ----
\\
+
+ 0 to 31 and 127 to 255
+ non-printable
octets
+ '\\xxx'> (octal value)
+ SELECT '\\001'::bytea;
+ \001
+
+
! The requirement to escape non-printable
octets actually
! varies depending on locale settings. In some instances you can get away
! with leaving them unescaped. Note that the result in each of the examples
! in was exactly one octet in
! length, even though the output representation of the zero octet and
! backslash are more than one character.
***************
*** 1206,1212 ****
32 to 126
printable
octets
! ASCII representation
SELECT '\\176'::bytea;
~
--- 1218,1224 ----
32 to 126
printable
octets
! client character set representation
SELECT '\\176'::bytea;
~
Index: src/backend/utils/adt/varlena.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/utils/adt/varlena.c,v
retrieving revision 1.106
diff -c -r1.106 varlena.c
*** src/backend/utils/adt/varlena.c 25 Sep 2003 06:58:05 -0000 1.106
--- src/backend/utils/adt/varlena.c 29 Nov 2003 05:28:40 -0000
***************
*** 186,195 ****
{
if (*vp == '\\')
len += 2;
! else if (isprint((unsigned char) *vp))
! len++;
! else
len += 4;
}
rp = result = (char *) palloc(len);
vp = VARDATA(vlena);
--- 186,195 ----
{
if (*vp == '\\')
len += 2;
! else if ((unsigned char) *vp < 0x20 || (unsigned char) *vp > 0x7e)
len += 4;
+ else
+ len++;
}
rp = result = (char *) palloc(len);
vp = VARDATA(vlena);
***************
*** 200,208 ****
*rp++ = '\\';
*rp++ = '\\';
}
! else if (isprint((unsigned char) *vp))
! *rp++ = *vp;
! else
{
val = *vp;
rp[0] = '\\';
--- 200,206 ----
*rp++ = '\\';
*rp++ = '\\';
}
! else if ((unsigned char) *vp < 0x20 || (unsigned char) *vp > 0x7e)
{
val = *vp;
rp[0] = '\\';
***************
*** 213,218 ****
--- 211,218 ----
rp[1] = DIG(val & 03);
rp += 4;
}
+ else
+ *rp++ = *vp;
}
*rp = '\0';
PG_RETURN_CSTRING(result);
Index: src/interfaces/libpq/fe-exec.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-exec.c,v
retrieving revision 1.153
diff -c -r1.153 fe-exec.c
*** src/interfaces/libpq/fe-exec.c 31 Oct 2003 17:43:10 -0000 1.153
--- src/interfaces/libpq/fe-exec.c 29 Nov 2003 05:28:45 -0000
***************
*** 2261,2267 ****
* '\0' == ASCII 0 == \\000
* '\'' == ASCII 39 == \'
* '\\' == ASCII 92 == \\\\
! * anything >= 0x80 ---> \\ooo (where ooo is an octal expression)
*/
unsigned char *
PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
--- 2261,2268 ----
* '\0' == ASCII 0 == \\000
* '\'' == ASCII 39 == \'
* '\\' == ASCII 92 == \\\\
! * anything < 0x20, or > 0x7e ---> \\ooo
! * (where ooo is an octal expression)
*/
unsigned char *
PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
***************
*** 2280,2286 ****
vp = bintext;
for (i = binlen; i > 0; i--, vp++)
{
! if (*vp == 0 || *vp >= 0x80)
len += 5; /* '5' is for '\\ooo' */
else if (*vp == '\'')
len += 2;
--- 2281,2287 ----
vp = bintext;
for (i = binlen; i > 0; i--, vp++)
{
! if (*vp < 0x20 || *vp > 0x7e)
len += 5; /* '5' is for '\\ooo' */
else if (*vp == '\'')
len += 2;
***************
*** 2299,2305 ****
for (i = binlen; i > 0; i--, vp++)
{
! if (*vp == 0 || *vp >= 0x80)
{
(void) sprintf(rp, "\\\\%03o", *vp);
rp += 5;
--- 2300,2306 ----
for (i = binlen; i > 0; i--, vp++)
{
! if (*vp < 0x20 || *vp > 0x7e)
{
(void) sprintf(rp, "\\\\%03o", *vp);
rp += 5;