@@ -109,14 +109,14 @@ free_statement(struct statement * stmt)
109109}
110110
111111static 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;
@@ -1110,6 +1110,13 @@ ecpg_build_params(struct statement * stmt)
11101110 struct variable * var ;
11111111 int desc_counter = 0 ;
11121112 int position = 0 ;
1113+ const char * value ;
1114+ bool std_strings = false;
1115+
1116+ /* Get standard_conforming_strings setting. */
1117+ value = PQparameterStatus (stmt -> connection -> connection , "standard_conforming_strings" );
1118+ if (value && strcmp (value , "on" ) == 0 )
1119+ std_strings = true;
11131120
11141121 /*
11151122 * If the type is one of the fill in types then we take the argument and
@@ -1300,7 +1307,7 @@ ecpg_build_params(struct statement * stmt)
13001307 * now tobeinserted points to an area that contains the next
13011308 * parameter; now find the position in the string where it belongs
13021309 */
1303- if ((position = next_insert (stmt -> command , position , stmt -> questionmarks ) + 1 ) == 0 )
1310+ if ((position = next_insert (stmt -> command , position , stmt -> questionmarks , std_strings ) + 1 ) == 0 )
13041311 {
13051312 /*
13061313 * We have an argument but we dont have the matched up placeholder
@@ -1387,7 +1394,7 @@ ecpg_build_params(struct statement * stmt)
13871394 }
13881395
13891396 /* Check if there are unmatched things left. */
1390- if (next_insert (stmt -> command , position , stmt -> questionmarks ) >= 0 )
1397+ if (next_insert (stmt -> command , position , stmt -> questionmarks , std_strings ) >= 0 )
13911398 {
13921399 ecpg_raise (stmt -> lineno , ECPG_TOO_FEW_ARGUMENTS ,
13931400 ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS , NULL );
0 commit comments