1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-18 17:41:14 +03:00

Backported bug fix for #2956.

This commit is contained in:
Michael Meskes 2007-02-27 13:26:50 +00:00
parent 8acd3cfb45
commit b128f53343

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.26.2.6 2006/04/24 09:46:32 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.26.2.7 2007/02/27 13:26:50 meskes Exp $ */
/* /*
* The aim is to get a simpler inteface to the database routines. * The aim is to get a simpler inteface to the database routines.
@ -38,33 +38,32 @@
static char * static char *
quote_postgres(char *arg, int lineno) quote_postgres(char *arg, int lineno)
{ {
char *res = (char *) ECPGalloc(2 * strlen(arg) + 3, lineno); char *res;
int i, int error;
ri = 0; size_t length;
size_t escaped_len;
size_t buffer_len;
/*
* if quote is false we just need to store things in a descriptor they
* will be quoted once they are inserted in a statement
*/
length = strlen(arg);
buffer_len = 2 * length + 1;
res = (char *) ECPGalloc(buffer_len + 2, lineno);
if (!res) if (!res)
return (res); return (res);
res[ri++] = '\''; error = 0;
escaped_len = PQescapeString(res+1, arg, buffer_len);
for (i = 0; arg[i]; i++, ri++) if (error)
{ {
switch (arg[i]) ECPGfree(res);
{ return NULL;
case '\'':
res[ri++] = '\'';
break;
case '\\':
res[ri++] = '\\';
break;
default:
;
}
res[ri] = arg[i];
} }
res[ri++] = '\''; res[0] = res[escaped_len+1] = '\'';
res[ri] = '\0'; res[escaped_len+2] = '\0';
ECPGfree(arg); ECPGfree(arg);
return res; return res;