From 3e9c4b223377c7f710cdba30ba25d2fe2984b1c8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 7 Aug 2013 13:56:36 +0200 Subject: [PATCH] Create test DB if 'database' GET param is set, but no matching DB is found --- code/TestSessionController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/TestSessionController.php b/code/TestSessionController.php index 936f41f..5932e16 100644 --- a/code/TestSessionController.php +++ b/code/TestSessionController.php @@ -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);