Subject: | DBD-mysql: createdb and dropdb should escape database name |
Date: | Thu, 14 May 2015 14:19:55 -0400 |
To: | bug-DBD-mysql [...] rt.cpan.org |
From: | Bertrand PROVOST <provost.bertrand [...] gmail.com> |
Hi,
I have found a bug with createdb and dropdb.
It fail when there is a minus: '-' in the name of database
Example
my $drh = DBI->install_driver("mysql");
$drh->func('createdb', 'test_minus', 'admin') or die 'failed
create test_minus';
$drh->func('dropdb', 'test_minus', 'admin') or die 'failed drop test_minus';
$drh->func('createdb', 'test-minus', 'admin') or die 'failed
create test-minus';
$drh->func('dropdb', 'test-minus', 'admin') or die 'failed drop test-minus';
$ perl bug.pl
failed create test-minus at bug.pl line 13.
Without escape this request is not valid
Show quoted text
mysql> CREATE DATABASE test-minus;
ERROR 1064 (42000): You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '-minus' at line 1
And after escaping
With escape this work:
Show quoted text mysql> CREATE DATABASE `test-minus`;
Query OK, 1 row affected (0.00 sec)
The problem seem to come from mysql.xs, line 139
strcpy(buffer, "CREATE DATABASE ");
strcat(buffer, dbname);
retval = mysql_real_query(sock, buffer, strlen(buffer));
free(buffer);
and line 159
strcpy(buffer, "DROP DATABASE ");
strcat(buffer, dbname);
retval = mysql_real_query(sock, buffer, strlen(buffer));
free(buffer);
--
Bertrand PROVOST