mirror of
https://github.com/postgres/postgres.git
synced 2025-05-21 15:54:08 +03:00
Backported bug fix for #2956.
This commit is contained in:
parent
355451be0e
commit
e9a97570fa
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.43.2.9 2007/02/06 09:41:52 meskes Exp $ */
|
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.43.2.10 2007/02/27 13:27:05 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,27 +38,45 @@
|
|||||||
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 + 3, lineno);
|
||||||
if (!res)
|
if (!res)
|
||||||
return (res);
|
return (res);
|
||||||
|
|
||||||
if (strchr(arg, '\\') != NULL)
|
error = 0;
|
||||||
res[ri++] = ESCAPE_STRING_SYNTAX;
|
escaped_len = PQescapeString(res+1, arg, buffer_len);
|
||||||
res[ri++] = '\'';
|
if (error)
|
||||||
|
|
||||||
for (i = 0; arg[i]; i++, ri++)
|
|
||||||
{
|
{
|
||||||
if (SQL_STR_DOUBLE(arg[i]))
|
ECPGfree(res);
|
||||||
res[ri++] = arg[i];
|
return NULL;
|
||||||
res[ri] = arg[i];
|
}
|
||||||
|
if (length == escaped_len)
|
||||||
|
{
|
||||||
|
res[0] = res[escaped_len+1] = '\'';
|
||||||
|
res[escaped_len+2] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We don't know if the target database is using
|
||||||
|
* standard_conforming_strings, so we always use E'' strings.
|
||||||
|
*/
|
||||||
|
memmove(res+2, res+1, escaped_len);
|
||||||
|
res[0] = ESCAPE_STRING_SYNTAX;
|
||||||
|
res[1] = res[escaped_len+2] = '\'';
|
||||||
|
res[escaped_len+3] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
res[ri++] = '\'';
|
|
||||||
res[ri] = '\0';
|
|
||||||
|
|
||||||
ECPGfree(arg);
|
ECPGfree(arg);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user