aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2017-10-26 10:16:04 +0200
committerMichael Meskes <meskes@postgresql.org>2017-10-26 10:40:03 +0200
commitc6a3968889046e1367ec6f6054f776433237631f (patch)
tree59b66c148dfd3b5651072ee9d5aa232c6a70c108 /src
parent9f7afb25b911f1591864d63e26eeaa2226f245fb (diff)
downloadpostgresql-c6a3968889046e1367ec6f6054f776433237631f.tar.gz
postgresql-c6a3968889046e1367ec6f6054f776433237631f.zip
Fixed handling of escape character in libecpg.
Patch by Tsunakawa Takayuki <tsunakawa.takay@jp.fujitsu.com>
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 36bc767c1e1..993cb49d74c 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -109,14 +109,14 @@ free_statement(struct statement * stmt)
}
static int
-next_insert(char *text, int pos, bool questionmarks)
+next_insert(char *text, int pos, bool questionmarks, bool std_strings)
{
bool string = false;
int p = pos;
for (; text[p] != '\0'; p++)
{
- if (text[p] == '\\') /* escape character */
+ if (string && !std_strings && text[p] == '\\') /* escape character */
p++;
else if (text[p] == '\'')
string = string ? false : true;
@@ -1104,6 +1104,13 @@ ecpg_build_params(struct statement * stmt)
struct variable *var;
int desc_counter = 0;
int position = 0;
+ const char *value;
+ bool std_strings = false;
+
+ /* Get standard_conforming_strings setting. */
+ value = PQparameterStatus(stmt->connection->connection, "standard_conforming_strings");
+ if (value && strcmp(value, "on") == 0)
+ std_strings = true;
/*
* If the type is one of the fill in types then we take the argument and
@@ -1294,7 +1301,7 @@ ecpg_build_params(struct statement * stmt)
* now tobeinserted points to an area that contains the next
* parameter; now find the position in the string where it belongs
*/
- if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
+ if ((position = next_insert(stmt->command, position, stmt->questionmarks, std_strings) + 1) == 0)
{
/*
* We have an argument but we dont have the matched up placeholder
@@ -1381,7 +1388,7 @@ ecpg_build_params(struct statement * stmt)
}
/* Check if there are unmatched things left. */
- if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
+ if (next_insert(stmt->command, position, stmt->questionmarks, std_strings) >= 0)
{
ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);