00001 <?php
00002
00013
00014 if (!defined('ADODB_DIR')) die();
00015
00016 class ADODB2_mysql extends ADODB_DataDict {
00017 var $databaseType = 'mysql';
00018 var $alterCol = ' MODIFY COLUMN';
00019 var $alterTableAddIndex = true;
00020 var $dropTable = 'DROP TABLE IF EXISTS %s';
00021
00022 var $dropIndex = 'DROP INDEX %s ON %s';
00023 var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s';
00024
00025 function MetaType($t,$len=-1,$fieldobj=false)
00026 {
00027 if (is_object($t)) {
00028 $fieldobj = $t;
00029 $t = $fieldobj->type;
00030 $len = $fieldobj->max_length;
00031 }
00032 $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment;
00033
00034 $len = -1;
00035 switch (strtoupper($t)) {
00036 case 'STRING':
00037 case 'CHAR':
00038 case 'VARCHAR':
00039 case 'TINYBLOB':
00040 case 'TINYTEXT':
00041 case 'ENUM':
00042 case 'SET':
00043 if ($len <= $this->blobSize) return 'C';
00044
00045 case 'TEXT':
00046 case 'LONGTEXT':
00047 case 'MEDIUMTEXT':
00048 return 'X';
00049
00050
00051
00052 case 'IMAGE':
00053 case 'LONGBLOB':
00054 case 'BLOB':
00055 case 'MEDIUMBLOB':
00056 return !empty($fieldobj->binary) ? 'B' : 'X';
00057
00058 case 'YEAR':
00059 case 'DATE': return 'D';
00060
00061 case 'TIME':
00062 case 'DATETIME':
00063 case 'TIMESTAMP': return 'T';
00064
00065 case 'FLOAT':
00066 case 'DOUBLE':
00067 return 'F';
00068
00069 case 'INT':
00070 case 'INTEGER': return $is_serial ? 'R' : 'I';
00071 case 'TINYINT': return $is_serial ? 'R' : 'I1';
00072 case 'SMALLINT': return $is_serial ? 'R' : 'I2';
00073 case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
00074 case 'BIGINT': return $is_serial ? 'R' : 'I8';
00075 default: return 'N';
00076 }
00077 }
00078
00079 function ActualType($meta)
00080 {
00081 switch(strtoupper($meta)) {
00082 case 'C': return 'VARCHAR';
00083 case 'XL':return 'LONGTEXT';
00084 case 'X': return 'TEXT';
00085
00086 case 'C2': return 'VARCHAR';
00087 case 'X2': return 'LONGTEXT';
00088
00089 case 'B': return 'LONGBLOB';
00090
00091 case 'D': return 'DATE';
00092 case 'T': return 'DATETIME';
00093 case 'L': return 'TINYINT';
00094
00095 case 'R':
00096 case 'I4':
00097 case 'I': return 'INTEGER';
00098 case 'I1': return 'TINYINT';
00099 case 'I2': return 'SMALLINT';
00100 case 'I8': return 'BIGINT';
00101
00102 case 'F': return 'DOUBLE';
00103 case 'N': return 'NUMERIC';
00104 default:
00105 return $meta;
00106 }
00107 }
00108
00109
00110 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
00111 {
00112 $suffix = '';
00113 if ($funsigned) $suffix .= ' UNSIGNED';
00114 if ($fnotnull) $suffix .= ' NOT NULL';
00115 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00116 if ($fautoinc) $suffix .= ' AUTO_INCREMENT';
00117 if ($fconstraint) $suffix .= ' '.$fconstraint;
00118 return $suffix;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
00143 {
00144 $sql = array();
00145
00146 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
00147 if ($this->alterTableAddIndex) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname";
00148 else $sql[] = sprintf($this->dropIndex, $idxname, $tabname);
00149
00150 if ( isset($idxoptions['DROP']) )
00151 return $sql;
00152 }
00153
00154 if ( empty ($flds) ) {
00155 return $sql;
00156 }
00157
00158 if (isset($idxoptions['FULLTEXT'])) {
00159 $unique = ' FULLTEXT';
00160 } elseif (isset($idxoptions['UNIQUE'])) {
00161 $unique = ' UNIQUE';
00162 } else {
00163 $unique = '';
00164 }
00165
00166 if ( is_array($flds) ) $flds = implode(', ',$flds);
00167
00168 if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname ";
00169 else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname;
00170
00171 $s .= ' (' . $flds . ')';
00172
00173 if ( isset($idxoptions[$this->upperName]) )
00174 $s .= $idxoptions[$this->upperName];
00175
00176 $sql[] = $s;
00177
00178 return $sql;
00179 }
00180 }
00181 ?>