1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-24 09:27:52 +03:00

Add E'' to internally created SQL strings that contain backslashes.

Improve code clarity by using macros for E'' processing.
This commit is contained in:
Bruce Momjian
2005-07-02 17:01:59 +00:00
parent 654efe6aaa
commit 74b49a8129
12 changed files with 91 additions and 89 deletions

View File

@@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.40 2005/06/02 12:35:11 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.41 2005/07/02 17:01:53 momjian Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -45,21 +45,14 @@ quote_postgres(char *arg, int lineno)
if (!res)
return (res);
if (strchr(arg, '\\') != NULL)
res[ri++] = ESCAPE_STRING_SYNTAX;
res[ri++] = '\'';
for (i = 0; arg[i]; i++, ri++)
{
switch (arg[i])
{
case '\'':
res[ri++] = '\'';
break;
case '\\':
res[ri++] = '\\';
break;
default:
;
}
if (SQL_STR_DOUBLE(arg[i]))
res[ri++] = arg[i];
res[ri] = arg[i];
}

View File

@@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.307 2005/02/10 08:06:35 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.308 2005/07/02 17:01:53 momjian Exp $ */
/* Copyright comment */
%{
@@ -4216,11 +4216,16 @@ Bconst: BCONST { $$ = make_name();};
Xconst: XCONST { $$ = make_name();};
Sconst: SCONST
{
$$ = (char *)mm_alloc(strlen($1) + 3);
$$[0]='\'';
strcpy($$+1, $1);
$$[strlen($1)+2]='\0';
$$[strlen($1)+1]='\'';
char *ret;
$$ = ret = (char *)mm_alloc(strlen($1) + 4);
if (strchr($1, '\\') != NULL)
*ret++ = ESCAPE_STRING_SYNTAX;
*ret++ = '\'';
strcpy(ret, $1);
ret += strlen($1);
*ret++ = '\'';
*ret++ = '\0';
free($1);
}
;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.169 2005/06/12 00:00:21 neilc Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.170 2005/07/02 17:01:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2368,23 +2368,9 @@ PQescapeString(char *to, const char *from, size_t length)
while (remaining > 0 && *source != '\0')
{
switch (*source)
{
case '\\':
*target++ = '\\';
*target++ = '\\';
break;
case '\'':
*target++ = '\'';
*target++ = '\'';
break;
default:
*target++ = *source;
break;
}
source++;
if (SQL_STR_DOUBLE(*source))
*target++ = *source;
*target++ = *source++;
remaining--;
}
@@ -2449,7 +2435,7 @@ PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
}
else if (*vp == '\'')
{
rp[0] = '\\';
rp[0] = '\'';
rp[1] = '\'';
rp += 2;
}