Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0af98a9

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

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/interfaces/ecpg/ecpglib/execute.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ free_statement(struct statement *stmt)
108108
}
109109

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

116116
for (; text[p] != '\0'; p++)
117117
{
118-
if (text[p] == '\\') /* escape character */
118+
if (string && !std_strings && text[p] == '\\') /* escape character */
119119
p++;
120120
else if (text[p] == '\'')
121121
string = string ? false : true;
@@ -1109,6 +1109,13 @@ ecpg_build_params(struct statement *stmt)
11091109
struct variable *var;
11101110
int desc_counter = 0;
11111111
int position = 0;
1112+
const char *value;
1113+
bool std_strings = false;
1114+
1115+
/* Get standard_conforming_strings setting. */
1116+
value = PQparameterStatus(stmt->connection->connection, "standard_conforming_strings");
1117+
if (value && strcmp(value, "on") == 0)
1118+
std_strings = true;
11121119

11131120
/*
11141121
* If the type is one of the fill in types then we take the argument and
@@ -1299,7 +1306,7 @@ ecpg_build_params(struct statement *stmt)
12991306
* now tobeinserted points to an area that contains the next
13001307
* parameter; now find the position in the string where it belongs
13011308
*/
1302-
if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1309+
if ((position = next_insert(stmt->command, position, stmt->questionmarks, std_strings) + 1) == 0)
13031310
{
13041311
/*
13051312
* We have an argument but we dont have the matched up placeholder
@@ -1386,7 +1393,7 @@ ecpg_build_params(struct statement *stmt)
13861393
}
13871394

13881395
/* Check if there are unmatched things left. */
1389-
if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
1396+
if (next_insert(stmt->command, position, stmt->questionmarks, std_strings) >= 0)
13901397
{
13911398
ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
13921399
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);

0 commit comments

Comments
 (0)