Bug #14358 mysql client parser error with "use foo;" command (database names <= 3 chars)
Submitted: 26 Oct 2005 22:40 Modified: 1 Nov 2005 21:30
Reporter: Timothy Smith
Status: Closed
Category:Client Severity:S2 (Serious)
Version:5.0.15 OS:Any (any)
Assigned to: Timothy Smith Target Version:

[26 Oct 2005 22:40] Timothy Smith
Description:
Run these two commands from the mysql client:

create database abc;
use abc;

It gives an error:

mysql> use abc;
ERROR 1049 (42000): Unknown database 'abc;'

This works:

use abc

If the database name has at least 4 characters, then it works fine.  If it has 3 or less
characters, then the above error happens.

How to repeat:

See Description.  This was tested on Windows, Linux & FreeBSD.  MySQL 5.0.13 does *not*
have this problem.  The latest BK code, and also 5.0.15-ga, do have it.

Suggested fix:

none, yet.  (Use mysql binary from 5.0.13 or earlier, which don't have this problem.)
[28 Oct 2005 0:25] Timothy Smith
This bug was introduced in revision 1.178.1.1 of mysql.cc:

@@ -1100,12 +1102,16 @@
 root       1.121      |     while (my_isspace(charset_info,*name))
 sasha      1.1        |       name++;
 jani       1.157      |     /*
-jani       1.157      |       As special case we allow row that starts with word
delimiter
-jani       1.157      |       to be able to change delimiter if someone has delimiter
'delimiter'.
+monty      1.178.1.1  |       If there is an \\g in the row or if the row has a
delimiter but
+monty      1.178.1.1  |       this is not a delimiter command, let add_line() take care
of
+monty      1.178.1.1  |       parsing the row and calling find_command()
 jani       1.157      |     */
 jani       1.157      |     if (strstr(name, "\\g") || (strstr(name, delimiter) &&
-jani       1.157      | 				strncmp(name, "delimiter", 9)))
-sasha      1.1        |       return ((COMMANDS *) 0);
+monty      1.178.1.1  |                                 strlen(name) >= 9 &&
+monty      1.178.1.1  |                                
my_strnncoll(charset_info,(uchar*) name,
+monty      1.178.1.1  |                                              9,
+monty      1.178.1.1  |                                              (const uchar*)
"delimiter", 9)))
+monty      1.178.1.1  |       DBUG_RETURN((COMMANDS *) 0);
 sasha      1.1        |     if ((end=strcont(name," \t")))
 sasha      1.1        |     {
 sasha      1.1        |       len=(uint) (end - name);

Here monty added a test to see if strlen(name) >= 9 (9 == strlen("delimiter")).  This is
the wrong test.  I'm not yet sure exactly what the right test is here.
[28 Oct 2005 0:52] Timothy Smith
I am attaching a patch as a file.  Sorry, I can't commit it myself yet (BK keys are messed
up for me still).

Here is the change, just for easy viewing:

-                                strlen(name) >= 9 &&
-                                my_strnncoll(charset_info,(uchar*) name,
-                                             9,
-                                             (const uchar*) "delimiter", 9)))
+                                !(strlen(name) >= 9 &&
+                                  !my_strnncoll(charset_info,
+                                                (uchar*) name, 9,
+                                                (const uchar*) "delimiter",
+                                                9))))
[28 Oct 2005 0:54] Timothy Smith
patch against mysql.cc to fix this bug

Attachment: bug-14358.diff (application/octet-stream, text), 946 bytes.

[28 Oct 2005 1:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/31588
[1 Nov 2005 21:00] Timothy Smith
Pushed, will be fixed in release 5.0.16.
[1 Nov 2005 21:30] Paul DuBois
Noted in 5.0.16 changelog.
[28 Aug 2007 0:20] karan vir singh ghattoraya
look i have a problem here it is if you can help me i will be grateful here it is 
ERROR 1049 (42000): Unknown database 'n´;'
and hers the command i used  
mysql> LOAD DATA LOCAL INFILE ´/path/pet.txt´ INTO TABE pet
    -> LINES TERMINATED BY ´\r\n´;
and im using linux and im an 11 year old kid but plese help me