summaryrefslogtreecommitdiff
path: root/client/mysql.cc
diff options
context:
space:
mode:
authorChad MILLER <chad@mysql.com>2008-12-11 12:26:03 -0500
committerChad MILLER <chad@mysql.com>2008-12-11 12:26:03 -0500
commitd84690c92d165e0335da16a7e95b10ac5684420e (patch)
tree3a6f45eb60eb44c5037ba8c027beb16f6091fa26 /client/mysql.cc
parentd2cd545b53397f36572001def335cf75c86570cf (diff)
downloadmariadb-git-d84690c92d165e0335da16a7e95b10ac5684420e.tar.gz
Bug#33812: mysql client incorrectly parsing DELIMITER
Fix parsing of mysql client commands, especially in relation to single-line comments when --comments was specified. This is a little tricky, because we need to allow single-line comments in the middle of statements, but we don't want to allow client commands in the middle of statements. So in comment-preservation mode, we go ahead and send single-line comments to the server immediately when we encounter them on their own. This is still slightly flawed, in that it does not handle a single-line comment with leading spaces, followed by a client-side command when --comment has been enabled. But this isn't a new problem, and it is quite an edge condition. Fixing it would require a more extensive overall of how the mysql client parses commands.
Diffstat (limited to 'client/mysql.cc')
-rw-r--r--client/mysql.cc49
1 files changed, 17 insertions, 32 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 9b14f9fb3ef..20f87d5cdcd 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1998,7 +1998,7 @@ static bool add_line(String &buffer,char *line,char *in_string,
{
if (!preserve_comments)
{
- // Skip spaces at the beggining of a statement
+ // Skip spaces at the beginning of a statement
if (my_isspace(charset_info,inchar) && (out == line) &&
buffer.is_empty())
continue;
@@ -2081,37 +2081,6 @@ static bool add_line(String &buffer,char *line,char *in_string,
continue;
}
}
- else if (!*ml_comment && !*in_string &&
- (end_of_line - pos) >= 10 &&
- !my_strnncoll(charset_info, (uchar*) pos, 10,
- (const uchar*) "delimiter ", 10))
- {
- // Flush previously accepted characters
- if (out != line)
- {
- buffer.append(line, (uint32) (out - line));
- out= line;
- }
-
- // Flush possible comments in the buffer
- if (!buffer.is_empty())
- {
- if (com_go(&buffer, 0) > 0) // < 0 is not fatal
- DBUG_RETURN(1);
- buffer.length(0);
- }
-
- /*
- Delimiter wants the get rest of the given line as argument to
- allow one to change ';' to ';;' and back
- */
- buffer.append(pos);
- if (com_delimiter(&buffer, pos) > 0)
- DBUG_RETURN(1);
-
- buffer.length(0);
- break;
- }
else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
{
// Found a statement. Continue parsing after the delimiter
@@ -2174,8 +2143,24 @@ static bool add_line(String &buffer,char *line,char *in_string,
// comment to end of line
if (preserve_comments)
+ {
+ bool started_with_nothing= !buffer.length();
+
buffer.append(pos);
+ /*
+ A single-line comment by itself gets sent immediately so that
+ client commands (delimiter, status, etc) will be interpreted on
+ the next line.
+ */
+ if (started_with_nothing)
+ {
+ if (com_go(&buffer, 0) > 0) // < 0 is not fatal
+ DBUG_RETURN(1);
+ buffer.length(0);
+ }
+ }
+
break;
}
else if (!*in_string && inchar == '/' && *(pos+1) == '*' &&