From 04904076fe126c2dca6a69a8eebbbf0b5c58a17d Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Wed, 26 Feb 2014 16:32:40 +0100 Subject: [PATCH] MDL-44377 dml: enforce non-empty prefix for sqlsrv Only MySQL is allowed to run Moodle instances without (with an empty) database prefix. The rationale is that "user" is a reserved word in every RDBMS but MySQL. Before this patch, installation was breaking badly, when the "user" CREATE TABLE statement was issued. With this patch the error is shown earlier (on connection) preventing any advance/use of the database. This check is present in all the drivers, just sqlsrv was missing it. --- lib/dml/sqlsrv_native_moodle_database.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/dml/sqlsrv_native_moodle_database.php b/lib/dml/sqlsrv_native_moodle_database.php index aae80a3be19c2..0b9dcaa50ce55 100644 --- a/lib/dml/sqlsrv_native_moodle_database.php +++ b/lib/dml/sqlsrv_native_moodle_database.php @@ -145,6 +145,11 @@ public function get_configuration_hints() { * @throws dml_connection_exception if error */ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) { + if ($prefix == '' and !$this->external) { + // Enforce prefixes for everybody but mysql. + throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily()); + } + $driverstatus = $this->driver_installed(); if ($driverstatus !== true) {