summaryrefslogtreecommitdiff
path: root/statement.c
diff options
context:
space:
mode:
authorHiroshi Inoue2017-08-10 22:22:54 +0000
committerHiroshi Inoue2017-08-14 03:04:06 +0000
commit21a2f3cdb2607d36eded44e51c29b3d8ef67300e (patch)
tree984e6b44c70bf5313a19f8952f39b4a6e1b82a92 /statement.c
parent79727ea0eca97a6b1f403e7795cb99dca3e4fbac (diff)
Handle '$'s in identifiers correctly.
Also take multibyte characters into account in identifiers.
Diffstat (limited to 'statement.c')
-rw-r--r--statement.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/statement.c b/statement.c
index acbe40f..692d93b 100644
--- a/statement.c
+++ b/statement.c
@@ -908,7 +908,8 @@ SC_scanQueryAndCountParams(const char *query, const ConnectionClass *conn,
const char *sptr, *tstr, *tag = NULL;
size_t taglen = 0;
char tchar, bchar, escape_in_literal = '\0';
- char in_literal = FALSE, in_identifier = FALSE,
+ char in_literal = FALSE, in_ident_keyword = FALSE,
+ in_dquote_identifier = FALSE,
in_dollar_quote = FALSE, in_escape = FALSE,
in_line_comment = FALSE, del_found = FALSE;
int comment_level = 0;
@@ -931,6 +932,16 @@ SC_scanQueryAndCountParams(const char *query, const ConnectionClass *conn,
{
if ((UCHAR) tchar >= 0x80)
bchar = tchar;
+ if (in_dquote_identifier ||
+ in_literal ||
+ in_dollar_quote ||
+ in_escape ||
+ in_line_comment ||
+ comment_level > 0)
+ ;
+ else
+ in_ident_keyword = TRUE;
+
continue;
}
if (!multi && del_found)
@@ -942,6 +953,17 @@ SC_scanQueryAndCountParams(const char *query, const ConnectionClass *conn,
break;
}
}
+ if (in_ident_keyword)
+ {
+ if (isalnum(tchar) ||
+ DOLLAR_QUOTE == tchar)
+ {
+ bchar = tchar;
+ continue;
+ }
+ in_ident_keyword = FALSE;
+ }
+
if (in_dollar_quote)
{
if (tchar == DOLLAR_QUOTE)
@@ -965,10 +987,10 @@ SC_scanQueryAndCountParams(const char *query, const ConnectionClass *conn,
else if (tchar == LITERAL_QUOTE)
in_literal = FALSE;
}
- else if (in_identifier)
+ else if (in_dquote_identifier)
{
if (tchar == IDENTIFIER_QUOTE)
- in_identifier = FALSE;
+ in_dquote_identifier = FALSE;
}
else if (in_line_comment)
{
@@ -990,6 +1012,8 @@ SC_scanQueryAndCountParams(const char *query, const ConnectionClass *conn,
comment_level--;
}
}
+ else if (isalnum(tchar))
+ in_ident_keyword = TRUE;
else
{
if (tchar == '?')
@@ -1031,7 +1055,7 @@ SC_scanQueryAndCountParams(const char *query, const ConnectionClass *conn,
}
}
else if (tchar == IDENTIFIER_QUOTE)
- in_identifier = TRUE;
+ in_dquote_identifier = TRUE;
else if ('-' == tchar)
{
if ('-' == sptr[1])