"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/datadict/datadict-mysql.inc.php Source File", "datetime" => "Sat Dec 2 19:22:25 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>
00001 <?php 00002 00013 // security - hide paths 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'; // requires mysql 3.22 or later 00021 00022 var $dropIndex = 'DROP INDEX %s ON %s'; 00023 var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition! 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; // mysql max_length is not accurate 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 // php_mysql extension always returns 'blob' even if 'text' 00051 // so we have to check whether binary... 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 // return string must begin with space 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 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] 00123 [table_options] [select_statement] 00124 create_definition: 00125 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] 00126 [PRIMARY KEY] [reference_definition] 00127 or PRIMARY KEY (index_col_name,...) 00128 or KEY [index_name] (index_col_name,...) 00129 or INDEX [index_name] (index_col_name,...) 00130 or UNIQUE [INDEX] [index_name] (index_col_name,...) 00131 or FULLTEXT [INDEX] [index_name] (index_col_name,...) 00132 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...) 00133 [reference_definition] 00134 or CHECK (expr) 00135 */ 00136 00137 /* 00138 CREATE [UNIQUE|FULLTEXT] INDEX index_name 00139 ON tbl_name (col_name[(length)],... ) 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 ?>