Commit 41c377f5 authored by Hiroshi Inoue's avatar Hiroshi Inoue

Fix *escape* handling in copy_statement_with_parameters(was my fault).

parent 6054b332
...@@ -945,7 +945,7 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -945,7 +945,7 @@ copy_statement_with_parameters(StatementClass *stmt)
int param_number; int param_number;
Int2 param_ctype, Int2 param_ctype,
param_sqltype; param_sqltype;
char *old_statement = stmt->statement; char *old_statement = stmt->statement, oldchar;
char *new_statement = stmt->stmt_with_params; char *new_statement = stmt->stmt_with_params;
unsigned int new_stsize = 0; unsigned int new_stsize = 0;
SIMPLE_TIME st; SIMPLE_TIME st;
...@@ -999,10 +999,11 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -999,10 +999,11 @@ copy_statement_with_parameters(StatementClass *stmt)
for (opos = 0; opos < oldstmtlen; opos++) for (opos = 0; opos < oldstmtlen; opos++)
{ {
oldchar = old_statement[opos];
#ifdef MULTIBYTE #ifdef MULTIBYTE
if (multibyte_char_check(old_statement[opos]) != 0) if (multibyte_char_check(oldchar) != 0)
{ {
CVT_APPEND_CHAR(old_statement[opos]); CVT_APPEND_CHAR(oldchar);
continue; continue;
} }
/* /*
...@@ -1010,35 +1011,37 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1010,35 +1011,37 @@ copy_statement_with_parameters(StatementClass *stmt)
* 1-byte character. * 1-byte character.
*/ */
#endif #endif
/* Squeeze carriage-return/linefeed pairs to linefeed only */
if (old_statement[opos] == '\r' && opos + 1 < oldstmtlen &&
old_statement[opos + 1] == '\n')
continue;
else if (in_escape) /* escape check */ if (in_escape) /* escape check */
{ {
in_escape = FALSE; in_escape = FALSE;
CVT_APPEND_CHAR(old_statement[opos]); CVT_APPEND_CHAR(oldchar);
continue; continue;
} }
else if (in_quote || in_dquote) /* quote/double quote check */ else if (in_quote || in_dquote) /* quote/double quote check */
{ {
if (old_statement[opos] == '\'' && in_quote) if (oldchar == '\\')
in_escape = TRUE;
else if (oldchar == '\'' && in_quote)
in_quote = FALSE; in_quote = FALSE;
else if (old_statement[opos] == '\"' && in_dquote) else if (oldchar == '\"' && in_dquote)
in_dquote = FALSE; in_dquote = FALSE;
CVT_APPEND_CHAR(old_statement[opos]); CVT_APPEND_CHAR(oldchar);
continue; continue;
} }
/* /*
* From here we are guranteed to be in neither * From here we are guranteed to be in neither
* an escape nor a quote nor a double quote. * an escape, a quote nor a double quote.
*/ */
/* Squeeze carriage-return/linefeed pairs to linefeed only */
else if (oldchar == '\r' && opos + 1 < oldstmtlen &&
old_statement[opos + 1] == '\n')
continue;
/* /*
* Handle literals (date, time, timestamp) and ODBC scalar * Handle literals (date, time, timestamp) and ODBC scalar
* functions * functions
*/ */
else if (old_statement[opos] == '{') else if (oldchar == '{')
{ {
char *esc; char *esc;
char *begin = &old_statement[opos + 1]; char *begin = &old_statement[opos + 1];
...@@ -1064,7 +1067,7 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1064,7 +1067,7 @@ copy_statement_with_parameters(StatementClass *stmt)
else else
{ /* it's not a valid literal so just copy */ { /* it's not a valid literal so just copy */
*end = '}'; *end = '}';
CVT_APPEND_CHAR(old_statement[opos]); CVT_APPEND_CHAR(oldchar);
continue; continue;
} }
...@@ -1078,15 +1081,15 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1078,15 +1081,15 @@ copy_statement_with_parameters(StatementClass *stmt)
* so. All the queries I've seen expect the driver to put quotes * so. All the queries I've seen expect the driver to put quotes
* if needed. * if needed.
*/ */
else if (old_statement[opos] == '?') else if (oldchar == '?')
; /* ok */ ; /* ok */
else else
{ {
if (old_statement[opos] == '\'') if (oldchar == '\'')
in_quote = TRUE; in_quote = TRUE;
else if (old_statement[opos] == '\\') else if (oldchar == '\\')
in_escape = TRUE; in_escape = TRUE;
else if (old_statement[opos] == '\"') else if (oldchar == '\"')
in_dquote = TRUE; in_dquote = TRUE;
else if (check_select_into && /* select into check */ else if (check_select_into && /* select into check */
opos > 0 && opos > 0 &&
...@@ -1097,7 +1100,7 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1097,7 +1100,7 @@ copy_statement_with_parameters(StatementClass *stmt)
memmove(new_statement, new_statement + declare_pos, npos - declare_pos); memmove(new_statement, new_statement + declare_pos, npos - declare_pos);
npos -= declare_pos; npos -= declare_pos;
} }
CVT_APPEND_CHAR(old_statement[opos]); CVT_APPEND_CHAR(oldchar);
continue; continue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment