diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index c9f1c07f9..d06957b55 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -142,7 +142,15 @@ class MySQLDatabase extends Database { * Use with caution. */ public function dropDatabase() { - $this->query("DROP DATABASE $this->database"); + $this->dropDatabaseByName($this->database); + } + + /** + * Drop the database that this object is currently connected to. + * Use with caution. + */ + public function dropDatabaseByName($dbName) { + $this->query("DROP DATABASE \"$dbName\""); } /** @@ -171,6 +179,13 @@ class MySQLDatabase extends Database { $SQL_name = Convert::raw2sql($name); return $this->query("SHOW DATABASES LIKE '$SQL_name'")->value() ? true : false; } + + /** + * Returns a column + */ + public function allDatabaseNames() { + return $this->query("SHOW DATABASES")->column(); + } public function createTable($tableName, $fields = null, $indexes = null) { $fieldSchemas = $indexSchemas = ""; diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 1dc66de96..e533648ee 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -240,6 +240,16 @@ class SapphireTest extends PHPUnit_Framework_TestCase { return $dbname; } + + static function delete_all_temp_dbs() { + foreach(DB::getConn()->allDatabaseNames() as $dbName) { + if(preg_match('/^tmpdb[0-9]+$/', $dbName)) { + DB::getConn()->dropDatabaseByName($dbName); + echo "