Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41c377f

Browse files
author
Hiroshi Inoue
committed
Fix *escape* handling in copy_statement_with_parameters(was my fault).
1 parent6054b33 commit41c377f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

‎src/interfaces/odbc/convert.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ copy_statement_with_parameters(StatementClass *stmt)
945945
intparam_number;
946946
Int2param_ctype,
947947
param_sqltype;
948-
char*old_statement=stmt->statement;
948+
char*old_statement=stmt->statement,oldchar;
949949
char*new_statement=stmt->stmt_with_params;
950950
unsignedintnew_stsize=0;
951951
SIMPLE_TIMEst;
@@ -999,46 +999,49 @@ copy_statement_with_parameters(StatementClass *stmt)
999999

10001000
for (opos=0;opos<oldstmtlen;opos++)
10011001
{
1002+
oldchar=old_statement[opos];
10021003
#ifdefMULTIBYTE
1003-
if (multibyte_char_check(old_statement[opos])!=0)
1004+
if (multibyte_char_check(oldchar)!=0)
10041005
{
1005-
CVT_APPEND_CHAR(old_statement[opos]);
1006+
CVT_APPEND_CHAR(oldchar);
10061007
continue;
10071008
}
10081009
/*
10091010
*From here we are guaranteed to handle a
10101011
*1-byte character.
10111012
*/
10121013
#endif
1013-
/* Squeeze carriage-return/linefeed pairs to linefeed only */
1014-
if (old_statement[opos]=='\r'&&opos+1<oldstmtlen&&
1015-
old_statement[opos+1]=='\n')
1016-
continue;
10171014

1018-
elseif (in_escape)/* escape check */
1015+
if (in_escape)/* escape check */
10191016
{
10201017
in_escape= FALSE;
1021-
CVT_APPEND_CHAR(old_statement[opos]);
1018+
CVT_APPEND_CHAR(oldchar);
10221019
continue;
10231020
}
10241021
elseif (in_quote||in_dquote)/* quote/double quote check */
10251022
{
1026-
if (old_statement[opos]=='\''&&in_quote)
1023+
if (oldchar=='\\')
1024+
in_escape= TRUE;
1025+
elseif (oldchar=='\''&&in_quote)
10271026
in_quote= FALSE;
1028-
elseif (old_statement[opos]=='\"'&&in_dquote)
1027+
elseif (oldchar=='\"'&&in_dquote)
10291028
in_dquote= FALSE;
1030-
CVT_APPEND_CHAR(old_statement[opos]);
1029+
CVT_APPEND_CHAR(oldchar);
10311030
continue;
10321031
}
10331032
/*
10341033
*From here we are guranteed to be in neither
1035-
*an escape nor a quote nor a double quote.
1034+
*an escape, a quote nor a double quote.
10361035
*/
1036+
/* Squeeze carriage-return/linefeed pairs to linefeed only */
1037+
elseif (oldchar=='\r'&&opos+1<oldstmtlen&&
1038+
old_statement[opos+1]=='\n')
1039+
continue;
10371040
/*
10381041
* Handle literals (date, time, timestamp) and ODBC scalar
10391042
* functions
10401043
*/
1041-
elseif (old_statement[opos]=='{')
1044+
elseif (oldchar=='{')
10421045
{
10431046
char*esc;
10441047
char*begin=&old_statement[opos+1];
@@ -1064,7 +1067,7 @@ copy_statement_with_parameters(StatementClass *stmt)
10641067
else
10651068
{/* it's not a valid literal so just copy */
10661069
*end='}';
1067-
CVT_APPEND_CHAR(old_statement[opos]);
1070+
CVT_APPEND_CHAR(oldchar);
10681071
continue;
10691072
}
10701073

@@ -1078,15 +1081,15 @@ copy_statement_with_parameters(StatementClass *stmt)
10781081
* so. All the queries I've seen expect the driver to put quotes
10791082
* if needed.
10801083
*/
1081-
elseif (old_statement[opos]=='?')
1084+
elseif (oldchar=='?')
10821085
;/* ok */
10831086
else
10841087
{
1085-
if (old_statement[opos]=='\'')
1088+
if (oldchar=='\'')
10861089
in_quote= TRUE;
1087-
elseif (old_statement[opos]=='\\')
1090+
elseif (oldchar=='\\')
10881091
in_escape= TRUE;
1089-
elseif (old_statement[opos]=='\"')
1092+
elseif (oldchar=='\"')
10901093
in_dquote= TRUE;
10911094
elseif (check_select_into&&/* select into check */
10921095
opos>0&&
@@ -1097,7 +1100,7 @@ copy_statement_with_parameters(StatementClass *stmt)
10971100
memmove(new_statement,new_statement+declare_pos,npos-declare_pos);
10981101
npos-=declare_pos;
10991102
}
1100-
CVT_APPEND_CHAR(old_statement[opos]);
1103+
CVT_APPEND_CHAR(oldchar);
11011104
continue;
11021105
}
11031106

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp