summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-exec.c
diff options
context:
space:
mode:
authorTatsuo Ishii <ishii@postgresql.org>2002-04-08 06:21:31 +0000
committerTatsuo Ishii <ishii@postgresql.org>2002-04-08 06:21:31 +0000
commit891ce19bcc1e2f9deba4a1c0eb22e6ee8dad5e04 (patch)
tree70762793b53530b738a4c793ba8e523e60c7e47c /src/interfaces/libpq/fe-exec.c
parentaf997458ebe32f1f9a10492bbe3aef549ada4806 (diff)
A backport patch.
Fix PQescapeBytea/PQunescapeBytea so that they handle bytes > 0x7f. This is necessary for mulibyte character sequences. See "[HACKERS] PQescapeBytea is not multibyte aware" thread posted around 2002/04/05 for more details.
Diffstat (limited to 'src/interfaces/libpq/fe-exec.c')
-rw-r--r--src/interfaces/libpq/fe-exec.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 123d7abd129..581288d1499 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.113 2001/10/25 05:50:13 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.113.2.1 2002/04/08 06:21:31 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -115,6 +115,7 @@ PQescapeString(char *to, const char *from, size_t length)
* '\0' == ASCII 0 == \\000
* '\'' == ASCII 39 == \'
* '\\' == ASCII 92 == \\\\
+ * anything >= 0x80 ---> \\ooo (where ooo is an octal expression)
*/
unsigned char *
PQescapeBytea(unsigned char *bintext, size_t binlen, size_t *bytealen)
@@ -131,40 +132,39 @@ PQescapeBytea(unsigned char *bintext, size_t binlen, size_t *bytealen)
len = 1;
vp = bintext;
- for (i = binlen; i != 0; i--, vp++)
+ for (i = binlen; i > 0; i--, vp++)
{
- if (*vp == 0)
- len += 5;
- else if (*vp == 39)
+ if (*vp == 0 || *vp >= 0x80)
+ len += 5; /* '5' is for '\\ooo' */
+ else if (*vp == '\'')
len += 2;
- else if (*vp == 92)
+ else if (*vp == '\\')
len += 4;
else
len++;
}
rp = result = (unsigned char *) malloc(len);
+ if (rp == NULL)
+ return NULL;
+
vp = bintext;
*bytealen = len;
- for (i = binlen; i != 0; i--, vp++)
+ for (i = binlen; i > 0; i--, vp++)
{
- if (*vp == 0)
+ if (*vp == 0 || *vp >= 0x80)
{
- rp[0] = '\\';
- rp[1] = '\\';
- rp[2] = '0';
- rp[3] = '0';
- rp[4] = '0';
+ (void)sprintf(rp,"\\\\%03o",*vp);
rp += 5;
}
- else if (*vp == 39)
+ else if (*vp == '\'')
{
rp[0] = '\\';
rp[1] = '\'';
rp += 2;
}
- else if (*vp == 92)
+ else if (*vp == '\\')
{
rp[0] = '\\';
rp[1] = '\\';