mirror of
https://github.com/moodle/moodle.git
synced 2025-07-25 00:02:18 +02:00
MDL-32003 fix phpdocs in DDL layer
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -15,12 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Mysql specific SQL code generator.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage ddl_generator
|
||||
* @package core_ddl
|
||||
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* 2001-3001 Eloy Lafuente (stronk7) http://contiento.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@@ -30,55 +27,72 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/ddl/sql_generator.php');
|
||||
|
||||
/// This class generate SQL code to be used against MySQL
|
||||
/// It extends XMLDBgenerator so everything can be
|
||||
/// overridden as needed to generate correct SQL.
|
||||
|
||||
/**
|
||||
* This class generate SQL code to be used against MySQL
|
||||
* It extends XMLDBgenerator so everything can be
|
||||
* overridden as needed to generate correct SQL.
|
||||
*
|
||||
* @package core_ddl
|
||||
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
* 2001-3001 Eloy Lafuente (stronk7) http://contiento.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class mysql_sql_generator extends sql_generator {
|
||||
|
||||
/// Only set values that are different from the defaults present in XMLDBgenerator
|
||||
// Only set values that are different from the defaults present in XMLDBgenerator
|
||||
|
||||
public $quote_string = '`'; // String used to quote names
|
||||
/** @var string Used to quote names. */
|
||||
public $quote_string = '`';
|
||||
|
||||
public $default_for_char = ''; // To define the default to set for NOT NULLs CHARs without default (null=do nothing)
|
||||
/** @var string To define the default to set for NOT NULLs CHARs without default (null=do nothing).*/
|
||||
public $default_for_char = '';
|
||||
|
||||
public $drop_default_value_required = true; //To specify if the generator must use some DEFAULT clause to drop defaults
|
||||
public $drop_default_value = NULL; //The DEFAULT clause required to drop defaults
|
||||
/** @var bool To specify if the generator must use some DEFAULT clause to drop defaults.*/
|
||||
public $drop_default_value_required = true;
|
||||
|
||||
public $primary_key_name = ''; //To force primary key names to one string (null=no force)
|
||||
/** @var string The DEFAULT clause required to drop defaults.*/
|
||||
public $drop_default_value = null;
|
||||
|
||||
public $drop_primary_key = 'ALTER TABLE TABLENAME DROP PRIMARY KEY'; // Template to drop PKs
|
||||
// with automatic replace for TABLENAME and KEYNAME
|
||||
/** @var string To force primary key names to one string (null=no force).*/
|
||||
public $primary_key_name = '';
|
||||
|
||||
public $drop_unique_key = 'ALTER TABLE TABLENAME DROP KEY KEYNAME'; // Template to drop UKs
|
||||
// with automatic replace for TABLENAME and KEYNAME
|
||||
/** @var string Template to drop PKs. 'TABLENAME' and 'KEYNAME' will be replaced from this template.*/
|
||||
public $drop_primary_key = 'ALTER TABLE TABLENAME DROP PRIMARY KEY';
|
||||
|
||||
public $drop_foreign_key = 'ALTER TABLE TABLENAME DROP FOREIGN KEY KEYNAME'; // Template to drop FKs
|
||||
// with automatic replace for TABLENAME and KEYNAME
|
||||
/** @var string Template to drop UKs. 'TABLENAME' and 'KEYNAME' will be replaced from this template.*/
|
||||
public $drop_unique_key = 'ALTER TABLE TABLENAME DROP KEY KEYNAME';
|
||||
|
||||
public $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
|
||||
public $sequence_name = 'auto_increment'; //Particular name for inline sequences in this generator
|
||||
/** @var string Template to drop FKs. 'TABLENAME' and 'KEYNAME' will be replaced from this template.*/
|
||||
public $drop_foreign_key = 'ALTER TABLE TABLENAME DROP FOREIGN KEY KEYNAME';
|
||||
|
||||
/** @var bool True if the generator needs to add extra code to generate the sequence fields.*/
|
||||
public $sequence_extra_code = false;
|
||||
|
||||
/** @var string The particular name for inline sequences in this generator.*/
|
||||
public $sequence_name = 'auto_increment';
|
||||
|
||||
public $add_after_clause = true; // Does the generator need to add the after clause for fields
|
||||
|
||||
public $concat_character = null; //Characters to be used as concatenation operator. If not defined
|
||||
//MySQL CONCAT function will be use
|
||||
/** @var string Characters to be used as concatenation operator.*/
|
||||
public $concat_character = null;
|
||||
|
||||
public $alter_column_sql = 'ALTER TABLE TABLENAME MODIFY COLUMN COLUMNSPECS'; //The SQL template to alter columns
|
||||
/** @var string The SQL template to alter columns where the 'TABLENAME' and 'COLUMNSPECS' keywords are dynamically replaced.*/
|
||||
public $alter_column_sql = 'ALTER TABLE TABLENAME MODIFY COLUMN COLUMNSPECS';
|
||||
|
||||
public $drop_index_sql = 'ALTER TABLE TABLENAME DROP INDEX INDEXNAME'; //SQL sentence to drop one index
|
||||
//TABLENAME, INDEXNAME are dynamically replaced
|
||||
/** @var string SQL sentence to drop one index where 'TABLENAME', 'INDEXNAME' keywords are dynamically replaced.*/
|
||||
public $drop_index_sql = 'ALTER TABLE TABLENAME DROP INDEX INDEXNAME';
|
||||
|
||||
public $rename_index_sql = null; //SQL sentence to rename one index (MySQL doesn't support this!)
|
||||
//TABLENAME, OLDINDEXNAME, NEWINDEXNAME are dynamically replaced
|
||||
/** @var string SQL sentence to rename one index where 'TABLENAME', 'OLDINDEXNAME' and 'NEWINDEXNAME' are dynamically replaced.*/
|
||||
public $rename_index_sql = null;
|
||||
|
||||
public $rename_key_sql = null; //SQL sentence to rename one key (MySQL doesn't support this!)
|
||||
//TABLENAME, OLDKEYNAME, NEWKEYNAME are dynamically replaced
|
||||
/** @var string SQL sentence to rename one key 'TABLENAME', 'OLDKEYNAME' and 'NEWKEYNAME' are dynamically replaced.*/
|
||||
public $rename_key_sql = null;
|
||||
|
||||
/**
|
||||
* Reset a sequence to the id field of a table.
|
||||
* @param string $table name of table or xmldb_table object
|
||||
* @return array sql commands to execute
|
||||
*
|
||||
* @param xmldb_table|string $table name of table or the table object.
|
||||
* @return array of sql statements
|
||||
*/
|
||||
public function getResetSequenceSQL($table) {
|
||||
|
||||
@@ -96,7 +110,11 @@ class mysql_sql_generator extends sql_generator {
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to create it (inside one array)
|
||||
* to create it (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table An xmldb_table instance.
|
||||
* @return array An array of SQL statements, starting with the table creation SQL followed
|
||||
* by any of its comments, indexes and sequence creation SQL statements.
|
||||
*/
|
||||
public function getCreateTableSQL($xmldb_table) {
|
||||
// first find out if want some special db engine
|
||||
@@ -124,7 +142,10 @@ class mysql_sql_generator extends sql_generator {
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to create temporary table (inside one array)
|
||||
* to create temporary table (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The xmldb_table object instance.
|
||||
* @return array of sql statements
|
||||
*/
|
||||
public function getCreateTempTableSQL($xmldb_table) {
|
||||
$this->temptables->add_temptable($xmldb_table->getName());
|
||||
@@ -150,7 +171,12 @@ class mysql_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one XMLDB Type, length and decimals, returns the DB proper SQL type
|
||||
* Given one XMLDB Type, length and decimals, returns the DB proper SQL type.
|
||||
*
|
||||
* @param int $xmldb_type The xmldb_type defined constant. XMLDB_TYPE_INTEGER and other XMLDB_TYPE_* constants.
|
||||
* @param int $xmldb_length The length of that data type.
|
||||
* @param int $xmldb_decimals The decimal places of precision of the data type.
|
||||
* @return string The DB defined data type.
|
||||
*/
|
||||
public function getTypeSQL($xmldb_type, $xmldb_length=null, $xmldb_decimals=null) {
|
||||
|
||||
@@ -219,26 +245,35 @@ class mysql_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needed to create its default
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needed to add its default
|
||||
* (usually invoked from getModifyDefaultSQL()
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The xmldb_table object instance.
|
||||
* @param xmldb_field $xmldb_field The xmldb_field object instance.
|
||||
* @return array Array of SQL statements to create a field's default.
|
||||
*/
|
||||
public function getCreateDefaultSQL($xmldb_table, $xmldb_field) {
|
||||
/// Just a wrapper over the getAlterFieldSQL() function for MySQL that
|
||||
/// is capable of handling defaults
|
||||
// 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 xmldb_field and the new name, returns the SQL statements
|
||||
* to rename it (inside one array)
|
||||
* MySQL is pretty different from the standard to justify this overloading
|
||||
* to rename it (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table related to $xmldb_field.
|
||||
* @param xmldb_field $xmldb_field The instance of xmldb_field to get the renamed field from.
|
||||
* @param string $newname The new name to rename the field to.
|
||||
* @return array The SQL statements for renaming the field.
|
||||
*/
|
||||
public function getRenameFieldSQL($xmldb_table, $xmldb_field, $newname) {
|
||||
// NOTE: MySQL is pretty different from the standard to justify this overloading.
|
||||
|
||||
/// Need a clone of xmldb_field to perform the change leaving original unmodified
|
||||
// Need a clone of xmldb_field to perform the change leaving original unmodified
|
||||
$xmldb_field_clone = clone($xmldb_field);
|
||||
|
||||
/// Change the name of the field to perform the change
|
||||
// Change the name of the field to perform the change
|
||||
$xmldb_field_clone->setName($newname);
|
||||
|
||||
$fieldsql = $this->getFieldSQL($xmldb_table, $xmldb_field_clone);
|
||||
@@ -252,15 +287,26 @@ class mysql_sql_generator extends sql_generator {
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop its default
|
||||
* (usually invoked from getModifyDefaultSQL()
|
||||
*
|
||||
* Note that this method may be dropped in future.
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The xmldb_table object instance.
|
||||
* @param xmldb_field $xmldb_field The xmldb_field object instance.
|
||||
* @return array Array of SQL statements to create a field's default.
|
||||
*
|
||||
* @todo MDL-31147 Moodle 2.1 - Drop getDropDefaultSQL()
|
||||
*/
|
||||
public function getDropDefaultSQL($xmldb_table, $xmldb_field) {
|
||||
/// Just a wrapper over the getAlterFieldSQL() function for MySQL that
|
||||
/// is capable of handling defaults
|
||||
// Just a wrapper over the getAlterFieldSQL() function for MySQL that
|
||||
// is capable of handling defaults
|
||||
return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code (in array) needed to add one comment to the table
|
||||
* Returns the code (array of statements) needed to add one comment to the table.
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The xmldb_table object instance.
|
||||
* @return array Array of SQL statements to add one comment to the table.
|
||||
*/
|
||||
function getCommentSQL ($xmldb_table) {
|
||||
$comment = '';
|
||||
@@ -273,25 +319,33 @@ class mysql_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg)
|
||||
* return if such name is currently in use (true) or no (false)
|
||||
* (invoked from getNameForObject()
|
||||
* Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg).
|
||||
*
|
||||
* (MySQL requires the whole xmldb_table object to be specified, so we add it always)
|
||||
*
|
||||
* This is invoked from getNameForObject().
|
||||
* Only some DB have this implemented.
|
||||
*
|
||||
* @param string $object_name The object's name to check for.
|
||||
* @param string $type The object's type (pk, uk, fk, ck, ix, uix, seq, trg).
|
||||
* @param string $table_name The table's name to check in
|
||||
* @return bool If such name is currently in use (true) or no (false)
|
||||
*/
|
||||
public function isNameInUse($object_name, $type, $table_name) {
|
||||
|
||||
/// Calculate the real table name
|
||||
// Calculate the real table name
|
||||
$xmldb_table = new xmldb_table($table_name);
|
||||
$tname = $this->getTableName($xmldb_table);
|
||||
|
||||
switch($type) {
|
||||
case 'ix':
|
||||
case 'uix':
|
||||
/// First of all, check table exists
|
||||
// First of all, check table exists
|
||||
$metatables = $this->mdb->get_tables();
|
||||
if (isset($metatables[$tname])) {
|
||||
/// Fetch all the indexes in the table
|
||||
// Fetch all the indexes in the table
|
||||
if ($indexes = $this->mdb->get_indexes($tname)) {
|
||||
/// Look for existing index in array
|
||||
// Look for existing index in array
|
||||
if (isset($indexes[$object_name])) {
|
||||
return true;
|
||||
}
|
||||
@@ -305,10 +359,11 @@ class mysql_sql_generator extends sql_generator {
|
||||
|
||||
/**
|
||||
* Returns an array of reserved words (lowercase) for this DB
|
||||
* @return array An array of database specific reserved words
|
||||
*/
|
||||
public static function getReservedWords() {
|
||||
/// This file contains the reserved words for MySQL databases
|
||||
/// from http://dev.mysql.com/doc/refman/6.0/en/reserved-words.html
|
||||
// This file contains the reserved words for MySQL databases
|
||||
// from http://dev.mysql.com/doc/refman/6.0/en/reserved-words.html
|
||||
$reserved_words = array (
|
||||
'accessible', 'add', 'all', 'alter', 'analyze', 'and', 'as', 'asc',
|
||||
'asensitive', 'before', 'between', 'bigint', 'binary',
|
||||
|
Reference in New Issue
Block a user