Skip to content

Commit

Permalink
MDL-39985 add explicit MariaDB support
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak authored and danpoltawski committed Jul 24, 2013
1 parent a60bc9a commit 17601a7
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 2 deletions.
1 change: 1 addition & 0 deletions admin/cli/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@

//Database types
$databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'),
'oci' => moodle_database::get_driver_instance('oci', 'native'),
'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
Expand Down
1 change: 1 addition & 0 deletions admin/environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@
</FEEDBACK>
</UNICODE>
<DATABASE level="required">
<VENDOR name="mariadb" version="5.3.5" />
<VENDOR name="mysql" version="5.1.33" />
<VENDOR name="postgres" version="8.3" />
<VENDOR name="mssql" version="9.0" />
Expand Down
1 change: 1 addition & 0 deletions auth/db/tests/db_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function init_auth_database() {
set_config('sybasequoting', '1', 'auth/db');
break;

case 'mariadb_native_moodle_database':
case 'mysqli_native_moodle_database':
set_config('type', 'mysqli', 'auth/db');
set_config('setupsql', "SET NAMES 'UTF-8'", 'auth/db');
Expand Down
2 changes: 1 addition & 1 deletion config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// will be stored. This database must already have been created //
// and a username/password created to access it. //

$CFG->dbtype = 'pgsql'; // 'pgsql', 'mysqli', 'mssql', 'sqlsrv' or 'oci'
$CFG->dbtype = 'pgsql'; // 'pgsql', 'mariadb', 'mysqli', 'mssql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodle'; // database name, eg moodle
Expand Down
1 change: 1 addition & 0 deletions enrol/database/tests/sync_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function init_enrol_database() {
set_config('dbsybasequoting', '1', 'enrol_database');
break;

case 'mariadb_native_moodle_database':
case 'mysqli_native_moodle_database':
set_config('dbtype', 'mysqli', 'enrol_database');
set_config('dbsetupsql', "SET NAMES 'UTF-8'", 'enrol_database');
Expand Down
1 change: 1 addition & 0 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
get_string('databasetypesub', 'install'));

$databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'),
'oci' => moodle_database::get_driver_instance('oci', 'native'),
'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
Expand Down
4 changes: 4 additions & 0 deletions lang/en/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@
$string['mysqlextensionisnotpresentinphp'] = 'PHP has not been properly configured with the MySQL extension so that it can communicate with MySQL. Please check your php.ini file or recompile PHP.';
$string['mysqli'] = 'Improved MySQL (mysqli)';
$string['mysqliextensionisnotpresentinphp'] = 'PHP has not been properly configured with the MySQLi extension so that it can communicate with MySQL. Please check your php.ini file or recompile PHP. MySQLi extension is not available for PHP 4.';
$string['nativemariadb'] = 'MariaDB (native/mariadb)';
$string['nativemariadbhelp'] = 'Now you need to configure the database where most Moodle data will be stored.
Database may be created if database user has needed permissions, username and password must already exist. Table prefix is optional.
This driver is not compatible with legacy MyISAM engine.';
$string['nativemysqli'] = 'Improved MySQL (native/mysqli)';
$string['nativemysqlihelp'] = 'Now you need to configure the database where most Moodle data will be stored.
Database may be created if database user has needed permissions, username and password must already exist. Table prefix is optional.';
Expand Down
110 changes: 110 additions & 0 deletions lib/dml/mariadb_native_moodle_database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Native MariaDB class representing moodle database interface.
*
* @package core_dml
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/moodle_database.php');
require_once(__DIR__.'/mysqli_native_moodle_database.php');
require_once(__DIR__.'/mysqli_native_moodle_recordset.php');
require_once(__DIR__.'/mysqli_native_moodle_temptables.php');

/**
* Native MariaDB class representing moodle database interface.
*
* @package core_dml
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mariadb_native_moodle_database extends mysqli_native_moodle_database {

/**
* Returns localised database type name
* Note: can be used before connect()
* @return string
*/
public function get_name() {
return get_string('nativemariadb', 'install');
}

/**
* Returns localised database configuration help.
* Note: can be used before connect()
* @return string
*/
public function get_configuration_help() {
return get_string('nativemariadbhelp', 'install');
}

/**
* Returns the database vendor.
* Note: can be used before connect()
* @return string The db vendor name, usually the same as db family name.
*/
public function get_dbvendor() {
return 'mariadb';
}

/**
* Returns more specific database driver type
* Note: can be used before connect()
* @return string db type mysqli, pgsql, oci, mssql, sqlsrv
*/
protected function get_dbtype() {
return 'mariadb';
}

/**
* It is time to require transactions everywhere.
*
* MyISAM is NOT supported!
*
* @return bool
*/
protected function transactions_supported() {
if ($this->external) {
return parent::transactions_supported();
}
return true;
}

/**
* Returns the current db engine.
*
* MyISAM is NOT supported!
*
* @return string or null MySQL engine name
*/
public function get_dbengine() {
if ($this->external) {
return null;
}

$engine = parent::get_dbengine();
if ($engine === 'MyISAM') {
debugging('MyISAM tables are not supported in MariaDB driver!');
$engine = 'XtraDB';
}
return $engine;
}
}
9 changes: 9 additions & 0 deletions lib/dml/moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ public static function get_driver_instance($type, $library, $external = false) {
return new $classname($external);
}

/**
* Returns the database vendor.
* Note: can be used before connect()
* @return string The db vendor name, usually the same as db family name.
*/
public function get_dbvendor() {
return $this->get_dbfamily();
}

/**
* Returns the database family type. (This sort of describes the SQL 'dialect')
* Note: can be used before connect()
Expand Down
2 changes: 1 addition & 1 deletion lib/environmentlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ function environment_check_database($version, $env_select) {
}

/// Now search the version we are using (depending of vendor)
$current_vendor = $DB->get_dbfamily();
$current_vendor = $DB->get_dbvendor();

$dbinfo = $DB->get_server_info();
$current_version = normalize_version($dbinfo['version']);
Expand Down

0 comments on commit 17601a7

Please sign in to comment.