📄 mysql.class.php
字号:
<?php // $Id: mysql.class.php,v 1.38.2.2 2009/03/02 18:53:16 stronk7 Exp $///////////////////////////////////////////////////////////////////////////// //// NOTICE OF COPYRIGHT //// //// Moodle - Modular Object-Oriented Dynamic Learning Environment //// http://moodle.com //// //// Copyright (C) 1999 onwards 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 XMLDBmysql 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 = ''; // 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 $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 /** * Creates one new XMLDBmysql */ function XMLDBmysql() { 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -