Create test DB if 'database' GET param is set, but no matching DB is found

This commit is contained in:
Ingo Schommer 2013-08-07 13:56:36 +02:00
parent 59327aff62
commit 3e9c4b2233

View File

@ -35,7 +35,15 @@ class TestSessionController extends Controller {
if(SapphireTest::using_temp_db()) return $this->renderWith('TestSession_inprogress');
// Database
if(!$request->getVar('database')) {
if($request->getVar('database')) {
$dbExists = (bool)DB::query(
sprintf("SHOW DATABASES LIKE '%s'", Convert::raw2sql($request->getVar('database')))
)->value();
} else {
$dbExists = false;
}
if(!$dbExists) {
// Create a new one with a randomized name
$dbname = SapphireTest::create_temp_db();
DB::set_alternative_database_name($dbname);