Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 104447
Status: rejected
Priority: 0/
Queue: DBD-mysql

People
Owner: CAPTTOFU [...] cpan.org
Requestors: provost.bertrand [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
Thanks for your bug report. Actually, I'm not sure if this is the best functionality of our module; you can also create a database using the DDL commands and you'll have much bigger control. https://dev.mysql.com/doc/refman/5.6/en/create-database.html So actually I think that, at least in time, we should remove the function. But maybe before we do this we should fix it first :D @Patrick, what is your idea on this? -- Michiel
MySQL deprecated dropdb and createdb in 5.7. I've removed these functions from the perldoc. The advise is to use the regular 'CREATE DATABASE' and 'DROP DATABASE' DDL statements.