4 @version v5.21.0 2021-02-27
5 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
6 @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
7 Released under both BSD license and Lesser GPL library license.
8 Whenever there is any discrepancy between the two licenses,
9 the BSD license will take precedence.
11 Set tabs to 4 for best viewing.
15 // security - hide paths
16 if (!defined('ADODB_DIR')) die();
18 class ADODB2_mysql
extends ADODB_DataDict
{
19 var $databaseType = 'mysql';
20 var $alterCol = ' MODIFY COLUMN';
21 var $alterTableAddIndex = true;
22 var $dropTable = 'DROP TABLE IF EXISTS %s'; // requires mysql 3.22 or later
24 var $dropIndex = 'DROP INDEX %s ON %s';
25 var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition!
27 public $blobAllowsNotNull = true;
29 function MetaType($t,$len=-1,$fieldobj=false)
35 $len = $fieldobj->max_length
;
37 $is_serial = is_object($fieldobj) && $fieldobj->primary_key
&& $fieldobj->auto_increment
;
39 $len = -1; // mysql max_length is not accurate
40 switch (strtoupper($t)) {
48 if ($len <= $this->blobSize
) return 'C';
55 // php_mysql extension always returns 'blob' even if 'text'
56 // so we have to check whether binary...
61 return !empty($fieldobj->binary
) ?
'B' : 'X';
64 case 'DATE': return 'D';
68 case 'TIMESTAMP': return 'T';
75 case 'INTEGER': return $is_serial ?
'R' : 'I';
76 case 'TINYINT': return $is_serial ?
'R' : 'I1';
77 case 'SMALLINT': return $is_serial ?
'R' : 'I2';
78 case 'MEDIUMINT': return $is_serial ?
'R' : 'I4';
79 case 'BIGINT': return $is_serial ?
'R' : 'I8';
80 default: return ADODB_DEFAULT_METATYPE
;
84 function ActualType($meta)
86 switch(strtoupper($meta)) {
87 case 'C': return 'VARCHAR';
88 case 'XL':return 'LONGTEXT';
89 case 'X': return 'TEXT';
91 case 'C2': return 'VARCHAR';
92 case 'X2': return 'LONGTEXT';
94 case 'B': return 'LONGBLOB';
96 case 'D': return 'DATE';
98 case 'T': return 'DATETIME';
99 case 'L': return 'TINYINT';
103 case 'I': return 'INTEGER';
104 case 'I1': return 'TINYINT';
105 case 'I2': return 'SMALLINT';
106 case 'I8': return 'BIGINT';
108 case 'F': return 'DOUBLE';
109 case 'N': return 'NUMERIC';
115 // return string must begin with space
116 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
119 if ($funsigned) $suffix .= ' UNSIGNED';
120 if ($fnotnull) $suffix .= ' NOT NULL';
121 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
122 if ($fautoinc) $suffix .= ' AUTO_INCREMENT';
123 if ($fconstraint) $suffix .= ' '.$fconstraint;
128 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
129 [table_options] [select_statement]
131 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
132 [PRIMARY KEY] [reference_definition]
133 or PRIMARY KEY (index_col_name,...)
134 or KEY [index_name] (index_col_name,...)
135 or INDEX [index_name] (index_col_name,...)
136 or UNIQUE [INDEX] [index_name] (index_col_name,...)
137 or FULLTEXT [INDEX] [index_name] (index_col_name,...)
138 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
139 [reference_definition]
144 CREATE [UNIQUE|FULLTEXT] INDEX index_name
145 ON tbl_name (col_name[(length)],... )
148 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
152 if ( isset($idxoptions['REPLACE']) ||
isset($idxoptions['DROP']) ) {
153 if ($this->alterTableAddIndex
) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname";
154 else $sql[] = sprintf($this->dropIndex
, $idxname, $tabname);
156 if ( isset($idxoptions['DROP']) )
160 if ( empty ($flds) ) {
164 if (isset($idxoptions['FULLTEXT'])) {
165 $unique = ' FULLTEXT';
166 } elseif (isset($idxoptions['UNIQUE'])) {
172 if ( is_array($flds) ) $flds = implode(', ',$flds);
174 if ($this->alterTableAddIndex
) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname ";
175 else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname;
177 $s .= ' (' . $flds . ')';
179 if ( isset($idxoptions[$this->upperName
]) )
180 $s .= $idxoptions[$this->upperName
];