Commit ac9e5527 authored by Aaron Wells's avatar Aaron Wells
Browse files

Upgrade our ADODB driver from the long-obsolete mysql driver to the actively...

Upgrade our ADODB driver from the long-obsolete mysql driver to the actively developed mysqli driver

Bug 1187964: The biggest improvement is that the ADODB mysqli driver actually supports transactions!

Change-Id: I8e55ea28cd6e6b8ed5c883646c1172d318af5554
parent 14298751
......@@ -45,9 +45,9 @@ $cfg = new stdClass();
/**
* database connection details
* valid values for dbtype are 'postgres8' and 'mysql5'
* valid values for dbtype are 'postgres' and 'mysql'
*/
$cfg->dbtype = 'postgres8';
$cfg->dbtype = 'postgres';
$cfg->dbhost = 'localhost';
$cfg->dbport = null;
$cfg->dbname = '';
......
......@@ -120,13 +120,20 @@ try {
// the error is instead.
ob_start();
// Transform $CFG->dbtype into the name of the ADODB driver we will use
if (is_postgres()) {
$CFG->dbtype = 'postgres7';
}
else if (is_mysql()) {
$CFG->dbtype = 'mysql';
// If they have mysqli, use it. Otherwise, fall back to the older "mysql" extension.
if (extension_loaded('mysqli')) {
$CFG->dbtype = 'mysqli';
}
else {
$CFG->dbtype = 'mysql';
}
}
$db = &ADONewConnection($CFG->dbtype);
if (empty($CFG->dbhost)) {
$CFG->dbhost = '';
......
......@@ -31,8 +31,8 @@ defined('INTERNAL') || die();
$string['phpversion'] = 'Mahara will not run on PHP < %s. Please upgrade your PHP version or move Mahara to a different host.';
$string['jsonextensionnotloaded'] = 'Your server configuration does not include the JSON extension. Mahara requires this in order to send some data to and from the browser. Please make sure that it is loaded in php.ini or install it if it is not installed.';
$string['pgsqldbextensionnotloaded'] = 'Your server configuration does not include the pgsql extension. Mahara requires this in order to store data in a relational database. Please make sure that it is loaded in php.ini or install it if it is not installed.';
$string['mysqldbextensionnotloaded'] = 'Your server configuration does not include the mysql extension. Mahara requires this in order to store data in a relational database. Please make sure that it is loaded in php.ini or install it if it is not installed.';
$string['unknowndbtype'] = 'Your server configuration references an unknown database type. Valid values are "postgres8" and "mysql5". Please change the database type setting in config.php.';
$string['mysqldbextensionnotloaded'] = 'Your server configuration does not include the mysqli or mysql extension. Mahara requires this in order to store data in a relational database. Please make sure that it is loaded in php.ini or install it if it is not installed.';
$string['unknowndbtype'] = 'Your server configuration references an unknown database type. Valid values are "postgres" and "mysql". Please change the database type setting in config.php.';
$string['domextensionnotloaded'] = 'Your server configuration does not include the dom extension. Mahara requires this in order to parse XML data from a variety of sources.';
$string['xmlextensionnotloaded'] = 'Your server configuration does not include the %s extension. Mahara requires this in order to parse XML data from a variety of sources. Please make sure that it is loaded in php.ini or install it if it is not installed.';
$string['gdextensionnotloaded'] = 'Your server configuration does not include the gd extension. Mahara requires this in order to perform resizes and other operations on uploaded images. Please make sure that it is loaded in php.ini or install it if it is not installed.';
......@@ -135,7 +135,7 @@ $string['timezoneidentifierunusable'] = 'PHP on your website host does not retur
$string['postmaxlessthanuploadmax'] = 'Your PHP post_max_size setting (%s) is smaller than your upload_max_filesize setting (%s). Uploads larger than %s will fail without displaying an error. Usually, post_max_size should be much larger than upload_max_filesize.';
$string['smallpostmaxsize'] = 'Your PHP post_max_size setting (%s) is very small. Uploads larger than %s will fail without displaying an error.';
$string['notenoughsessionentropy'] = 'Your PHP session.entropy_length setting is too small. Set it to at least 16 in your php.ini to ensure that generated session IDs are random and unpredictable enough.';
$string['switchtomysqli'] = 'The <strong>mysqli</strong> PHP extension is not installed on your server, so Mahara is falling back to the deprecated original <strong>mysql</strong> PHP extension. We recommend installing <a href="http://php.net/manual/en/book.mysqli.php">mysqli</a>.';
$string['noreplyaddressmissingorinvalid'] = 'The noreply address setting is either empty or has an invalid email address. Please check the configuration in the <a href="%s">site options in the email settings</a>.';
$string['openbasedirenabled'] = 'Your server has the php open_basedir restriction enabled.';
$string['openbasedirpaths'] = 'Mahara can only open files within the following path(s): %s.';
......
......@@ -843,7 +843,7 @@ class ActivityTypeWatchlist extends ActivityType {
// mysql compatibility (sigh...)
$casturl = 'CAST(? AS TEXT)';
if (get_config('dbtype') == 'mysql') {
if (is_mysql()) {
$casturl = 'CAST(? AS CHAR)'; // note, NOT varchar
}
$sql = 'SELECT u.*, p.method, ap.value AS lang, ' . $casturl . ' AS url
......
This diff is collapsed.
......@@ -119,6 +119,7 @@ function table_column($table, $oldfield, $field, $type='integer', $size='10',
case 'mysql':
case 'mysqlt':
case 'mysqli':
switch (strtolower($type)) {
case 'text':
......
......@@ -45,13 +45,15 @@ function ensure_sanity() {
throw new ConfigSanityException(get_string('jsonextensionnotloaded', 'error'));
}
switch (get_config('dbtype')) {
case 'postgres8':
case 'postgres':
case 'postgres8': // for legacy purposes we also accept "postgres8"
if (!extension_loaded('pgsql')) {
throw new ConfigSanityException(get_string('pgsqldbextensionnotloaded', 'error'));
}
break;
case 'mysql5':
if (!extension_loaded('mysql')) {
case 'mysql':
case 'mysql5': // for legacy purposes we also accept "mysql5"
if (!extension_loaded('mysqli') && !extension_loaded('mysql')) {
throw new ConfigSanityException(get_string('mysqldbextensionnotloaded', 'error'));
}
break;
......
......@@ -1349,5 +1349,9 @@ function site_warnings() {
$warnings[] = get_string('mbstringneeded', 'error');
}
if (get_config('dbtype') == 'mysql') {
$warnings[] = get_string('switchtomysqli', 'error');
}
return $warnings;
}
......@@ -171,7 +171,7 @@ class XMLDBmysql extends XMLDBGenerator {
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum
* (usually invoked from getModifyEnumSQL()
*/
function getCreateEnumSQL($xmldb_table, $xmldb_field) {
......@@ -179,8 +179,8 @@ class XMLDBmysql extends XMLDBGenerator {
return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum
* (usually invoked from getModifyEnumSQL()
*/
function getDropEnumSQL($xmldb_table, $xmldb_field) {
......@@ -189,7 +189,7 @@ class XMLDBmysql extends XMLDBGenerator {
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default
* (usually invoked from getModifyDefaultSQL()
*/
function getCreateDefaultSQL($xmldb_table, $xmldb_field) {
......@@ -217,7 +217,7 @@ class XMLDBmysql extends XMLDBGenerator {
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its default
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its default
* (usually invoked from getModifyDefaultSQL()
*/
function getDropDefaultSQL($xmldb_table, $xmldb_field) {
......@@ -253,7 +253,7 @@ class XMLDBmysql extends XMLDBGenerator {
}
/**
* Given one XMLDBTable returns one array with all the check constrainsts
* Given one XMLDBTable returns one array with all the check constrainsts
* in the table (fetched from DB)
* Each element contains the name of the constraint and its description
* If no check constraints are found, returns an empty array
......
<?php // $Id: mysql.class.php,v 1.29 2006/10/02 17:02:07 stronk7 Exp $
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/// This class generate SQL code to be used against MySQL
/// It extends XMLDBgenerator so everything can be
/// overriden as needed to generate correct SQL.
class XMLDBmysqli extends XMLDBGenerator {
/// Only set values that are different from the defaults present in XMLDBgenerator
var $quote_string = '`'; // String used to quote names
var $default_for_char = null; // To define the default to set for NOT NULLs CHARs without default (null=do nothing)
var $drop_default_clause_required = true; //To specify if the generator must use some DEFAULT clause to drop defaults
var $drop_default_clause = 'NULL'; //The DEFAULT clause required to drop defaults
var $primary_key_name = ''; //To force primary key names to one string (null=no force)
var $drop_primary_key = 'ALTER TABLE TABLENAME DROP PRIMARY KEY'; // Template to drop PKs
// with automatic replace for TABLENAME and KEYNAME
var $drop_unique_key = 'ALTER TABLE TABLENAME DROP KEY KEYNAME'; // Template to drop UKs
// with automatic replace for TABLENAME and KEYNAME
var $drop_foreign_key = 'ALTER TABLE TABLENAME DROP FOREIGN KEY KEYNAME'; // Template to drop FKs
// with automatic replace for TABLENAME and KEYNAME
var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
var $sequence_name = 'auto_increment'; //Particular name for inline sequences in this generator
var $enum_extra_code = false; //Does the generator need to add extra code to generate code for the enums in the table
var $table_extra_code = true;
var $add_after_clause = true; // Does the generator need to add the after clause for fields
var $concat_character = null; //Characters to be used as concatenation operator. If not defined
//MySQL CONCAT function will be use
var $alter_column_sql = 'ALTER TABLE TABLENAME MODIFY COLUMN COLUMNSPECS'; //The SQL template to alter columns
var $drop_index_sql = 'ALTER TABLE TABLENAME DROP INDEX INDEXNAME'; //SQL sentence to drop one index
//TABLENAME, INDEXNAME are dinamically replaced
var $rename_index_sql = null; //SQL sentence to rename one index (MySQL doesn't support this!)
//TABLENAME, OLDINDEXNAME, NEWINDEXNAME are dinamically replaced
var $rename_key_sql = null; //SQL sentence to rename one key (MySQL doesn't support this!)
//TABLENAME, OLDKEYNAME, NEWKEYNAME are dinamically replaced
var $unique_keys = true; // Does the generator build unique keys
var $foreign_keys = true; // Does the generator build foreign keys
/**
* Creates one new XMLDBmysqli
*/
function XMLDBmysqli() {
parent::XMLDBGenerator();
global $CFG;
$this->prefix = '';
$this->reserved_words = $this->getReservedWords();
}
/**
* Given one XMLDB Type, lenght and decimals, returns the DB proper SQL type
*/
function getTypeSQL ($xmldb_type, $xmldb_length=null, $xmldb_decimals=null) {
switch ($xmldb_type) {
case XMLDB_TYPE_INTEGER: // From http://mysql.com/doc/refman/5.0/en/numeric-types.html!
if (empty($xmldb_length)) {
$xmldb_length = 10;
}
if ($xmldb_length > 9) {
$dbtype = 'BIGINT';
} else if ($xmldb_length > 6) {
$dbtype = 'INT';
} else if ($xmldb_length > 4) {
$dbtype = 'MEDIUMINT';
} else if ($xmldb_length > 2) {
$dbtype = 'SMALLINT';
} else {
$dbtype = 'TINYINT';
}
$dbtype .= '(' . $xmldb_length . ')';
break;
case XMLDB_TYPE_NUMBER:
$dbtype = $this->number_type;
if (!empty($xmldb_length)) {
$dbtype .= '(' . $xmldb_length;
if (!empty($xmldb_decimals)) {
$dbtype .= ',' . $xmldb_decimals;
}
$dbtype .= ')';
}
break;
case XMLDB_TYPE_FLOAT:
$dbtype = 'DOUBLE';
if (!empty($xmldb_decimals)) {
if ($xmldb_decimals < 6) {
$dbtype = 'FLOAT';
}
}
if (!empty($xmldb_length)) {
$dbtype .= '(' . $xmldb_length;
if (!empty($xmldb_decimals)) {
$dbtype .= ',' . $xmldb_decimals;
}
$dbtype .= ')';
}
break;
case XMLDB_TYPE_CHAR:
$dbtype = 'VARCHAR';
if (empty($xmldb_length)) {
$xmldb_length='255';
}
$dbtype .= '(' . $xmldb_length . ')';
break;
case XMLDB_TYPE_TEXT:
if (empty($xmldb_length)) {
$xmldb_length = 'small';
}
if ($xmldb_length == 'small') {
$dbtype = 'TEXT';
} else if ($xmldb_length == 'medium') {
$dbtype = 'MEDIUMTEXT';
} else {
$dbtype = 'LONGTEXT';
}
break;
case XMLDB_TYPE_BINARY:
if (empty($xmldb_length)) {
$xmldb_length = 'small';
}
if ($xmldb_length == 'small') {
$dbtype = 'BLOB';
} else if ($xmldb_length == 'medium') {
$dbtype = 'MEDIUMBLOB';
} else {
$dbtype = 'LONGBLOB';
}
break;
case XMLDB_TYPE_DATETIME:
$dbtype = 'DATETIME';
}
return $dbtype;
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum
* (usually invoked from getModifyEnumSQL()
*/
function getCreateEnumSQL($xmldb_table, $xmldb_field) {
/// For MySQL, just alter the field
return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum
* (usually invoked from getModifyEnumSQL()
*/
function getDropEnumSQL($xmldb_table, $xmldb_field) {
/// For MySQL, just alter the field
return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default
* (usually invoked from getModifyDefaultSQL()
*/
function getCreateDefaultSQL($xmldb_table, $xmldb_field) {
/// Just a wrapper over the getAlterFieldSQL() function for MySQL that
/// is capable of handling defaults
return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
}
/**
* Given one correct XMLDBField and the new name, returns the SQL statements
* to rename it (inside one array)
* MySQL is pretty diferent from the standard to justify this oveloading
*/
function getRenameFieldSQL($xmldb_table, $xmldb_field, $newname) {
$results = array(); //Array where all the sentences will be stored
/// Change the name of the field to perform the change
$xmldb_field->setName($xmldb_field->getName() . ' ' . $newname);
$results[] = 'ALTER TABLE ' . $this->getTableName($xmldb_table) . ' CHANGE ' .
$this->getFieldSQL($xmldb_field);
return $results;
}
/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its default
* (usually invoked from getModifyDefaultSQL()
*/
function getDropDefaultSQL($xmldb_table, $xmldb_field) {
/// Just a wrapper over the getAlterFieldSQL() function for MySQL that
/// is capable of handling defaults
return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
}
/**
* Given one XMLDB Field, return its enum SQL
*/
function getEnumSQL ($xmldb_field) {
return 'enum(' . implode(', ', $xmldb_field->getEnumValues()) . ')';
}
function getTableExtraSQL($xmldb_table) {
return 'ENGINE=innodb'; // mahara only ever wants innodb because we want foreign keys!
}
/**
* Returns the code (in array) needed to add one comment to the table
*/
function getCommentSQL ($xmldb_table) {
$comment = '';
if ($xmldb_table->getComment()) {
$comment .= 'ALTER TABLE ' . $this->getTableName($xmldb_table);
$comment .= " COMMENT='" . substr($xmldb_table->getComment(), 0, 250) . "'";
}
return array($comment);
}
/**
* Given one XMLDBTable returns one array with all the check constrainsts
* in the table (fetched from DB)
* Each element contains the name of the constraint and its description
* If no check constraints are found, returns an empty array
* MySQL doesn't have check constraints in this implementation
*/
function getCheckConstraintsFromDB($xmldb_table) {
return array();
}
/**
* Returns an array of reserved words (lowercase) for this DB
*/
function getReservedWords() {
/// This file contains the reserved words for MySQL databases
/// from http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
$reserved_words = array (
'add', 'all', 'alter', 'analyze', 'and', 'as', 'asc',
'asensitive', 'before', 'between', 'bigint', 'binary',
'blob', 'both', 'by', 'call', 'cascade', 'case', 'change',
'char', 'character', 'check', 'collate', 'column', 'columns',
'condition', 'connection', 'constraint', 'continue',
'convert', 'create', 'cross', 'current_date', 'current_time',
'current_timestamp', 'current_user', 'cursor', 'database',
'databases', 'day_hour', 'day_microsecond',
'day_minute', 'day_second', 'dec', 'decimal', 'declare',
'default', 'delayed', 'delete', 'desc', 'describe',
'deterministic', 'distinct', 'distinctrow', 'div', 'double',
'drop', 'dual', 'each', 'else', 'elseif', 'enclosed', 'escaped',
'exists', 'exit', 'explain', 'false', 'fetch', 'float', 'float4',
'float8', 'for', 'force', 'foreign', 'from', 'fulltext', 'grant',
'group', 'having', 'high_priority', 'hour_microsecond',
'hour_minute', 'hour_second', 'if', 'ignore', 'in', 'index',
'infile', 'inner', 'inout', 'insensitive', 'insert', 'int', 'int1',
'int2', 'int3', 'int4', 'int8', 'integer', 'interval', 'into', 'is',
'iterate', 'join', 'key', 'keys', 'kill', 'leading', 'leave', 'left',
'like', 'limit', 'lines', 'load', 'localtime', 'localtimestamp',
'lock', 'long', 'longblob', 'longtext', 'loop', 'low_priority',
'match', 'mediumblob', 'mediumint', 'mediumtext',
'middleint', 'minute_microsecond', 'minute_second',
'mod', 'modifies', 'natural', 'not', 'no_write_to_binlog',
'null', 'numeric', 'on', 'optimize', 'option', 'optionally',
'or', 'order', 'out', 'outer', 'outfile', 'precision', 'primary',
'procedure', 'purge', 'raid0', 'read', 'reads', 'real',
'references', 'regexp', 'release', 'rename', 'repeat', 'replace',
'require', 'restrict', 'return', 'revoke', 'right', 'rlike', 'schema',
'schemas', 'second_microsecond', 'select', 'sensitive',
'separator', 'set', 'show', 'smallint', 'soname', 'spatial',
'specific', 'sql', 'sqlexception', 'sqlstate', 'sqlwarning',
'sql_big_result', 'sql_calc_found_rows', 'sql_small_result',
'ssl', 'starting', 'straight_join', 'table', 'terminated', 'then',
'tinyblob', 'tinyint', 'tinytext', 'to', 'trailing', 'trigger', 'true',
'undo', 'union', 'unique', 'unlock', 'unsigned', 'update',
'upgrade', 'usage', 'use', 'using', 'utc_date', 'utc_time',
'utc_timestamp', 'values', 'varbinary', 'varchar', 'varcharacter',
'varying', 'when', 'where', 'while', 'with', 'write', 'x509',
'xor', 'year_month', 'zerofill'
);
return $reserved_words;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment