Skip to content

Commit c6a3968

Browse files
author
Michael Meskes
committed
Fixed handling of escape character in libecpg.
Patch by Tsunakawa Takayuki <tsunakawa.takay@jp.fujitsu.com>
1 parent 9f7afb2 commit c6a3968

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ free_statement(struct statement * stmt)
109109
}
110110

111111
static int
112-
next_insert(char *text, int pos, bool questionmarks)
112+
next_insert(char *text, int pos, bool questionmarks, bool std_strings)
113113
{
114114
bool string = false;
115115
int p = pos;
116116

117117
for (; text[p] != '\0'; p++)
118118
{
119-
if (text[p] == '\\') /* escape character */
119+
if (string && !std_strings && text[p] == '\\') /* escape character */
120120
p++;
121121
else if (text[p] == '\'')
122122
string = string ? false : true;
@@ -1104,6 +1104,13 @@ ecpg_build_params(struct statement * stmt)
11041104
struct variable *var;
11051105
int desc_counter = 0;
11061106
int position = 0;
1107+
const char *value;
1108+
bool std_strings = false;
1109+
1110+
/* Get standard_conforming_strings setting. */
1111+
value = PQparameterStatus(stmt->connection->connection, "standard_conforming_strings");
1112+
if (value && strcmp(value, "on") == 0)
1113+
std_strings = true;
11071114

11081115
/*
11091116
* 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)
12941301
* now tobeinserted points to an area that contains the next
12951302
* parameter; now find the position in the string where it belongs
12961303
*/
1297-
if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1304+
if ((position = next_insert(stmt->command, position, stmt->questionmarks, std_strings) + 1) == 0)
12981305
{
12991306
/*
13001307
* We have an argument but we dont have the matched up placeholder
@@ -1381,7 +1388,7 @@ ecpg_build_params(struct statement * stmt)
13811388
}
13821389

13831390
/* Check if there are unmatched things left. */
1384-
if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
1391+
if (next_insert(stmt->command, position, stmt->questionmarks, std_strings) >= 0)
13851392
{
13861393
ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
13871394
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);

0 commit comments

Comments
 (0)