See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 3 /** 4 @version v5.20.16 12-Jan-2020 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. 10 11 Set tabs to 4 for best viewing. 12 13 */ 14 15 // security - hide paths 16 if (!defined('ADODB_DIR')) die(); 17 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 23 24 var $dropIndex = 'DROP INDEX %s ON %s'; 25 var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition! 26 27 function MetaType($t,$len=-1,$fieldobj=false) 28 { 29 if (is_object($t)) { 30 $fieldobj = $t; 31 $t = $fieldobj->type; 32 $len = $fieldobj->max_length; 33 } 34 $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment; 35 36 $len = -1; // mysql max_length is not accurate 37 switch (strtoupper($t)) { 38 case 'STRING': 39 case 'CHAR': 40 case 'VARCHAR': 41 case 'TINYBLOB': 42 case 'TINYTEXT': 43 case 'ENUM': 44 case 'SET': 45 if ($len <= $this->blobSize) return 'C'; 46 47 case 'TEXT': 48 case 'LONGTEXT': 49 case 'MEDIUMTEXT': 50 return 'X'; 51 52 // php_mysql extension always returns 'blob' even if 'text' 53 // so we have to check whether binary... 54 case 'IMAGE': 55 case 'LONGBLOB': 56 case 'BLOB': 57 case 'MEDIUMBLOB': 58 return !empty($fieldobj->binary) ? 'B' : 'X'; 59 60 case 'YEAR': 61 case 'DATE': return 'D'; 62 63 case 'TIME': 64 case 'DATETIME': 65 case 'TIMESTAMP': return 'T'; 66 67 case 'FLOAT': 68 case 'DOUBLE': 69 return 'F'; 70 71 case 'INT': 72 case 'INTEGER': return $is_serial ? 'R' : 'I'; 73 case 'TINYINT': return $is_serial ? 'R' : 'I1'; 74 case 'SMALLINT': return $is_serial ? 'R' : 'I2'; 75 case 'MEDIUMINT': return $is_serial ? 'R' : 'I4'; 76 case 'BIGINT': return $is_serial ? 'R' : 'I8'; 77 default: return 'N'; 78 } 79 } 80 81 function ActualType($meta) 82 { 83 switch(strtoupper($meta)) { 84 case 'C': return 'VARCHAR'; 85 case 'XL':return 'LONGTEXT'; 86 case 'X': return 'TEXT'; 87 88 case 'C2': return 'VARCHAR'; 89 case 'X2': return 'LONGTEXT'; 90 91 case 'B': return 'LONGBLOB'; 92 93 case 'D': return 'DATE'; 94 case 'TS': 95 case 'T': return 'DATETIME'; 96 case 'L': return 'TINYINT'; 97 98 case 'R': 99 case 'I4': 100 case 'I': return 'INTEGER'; 101 case 'I1': return 'TINYINT'; 102 case 'I2': return 'SMALLINT'; 103 case 'I8': return 'BIGINT'; 104 105 case 'F': return 'DOUBLE'; 106 case 'N': return 'NUMERIC'; 107 default: 108 return $meta; 109 } 110 } 111 112 // return string must begin with space 113 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) 114 { 115 $suffix = ''; 116 if ($funsigned) $suffix .= ' UNSIGNED'; 117 if ($fnotnull) $suffix .= ' NOT NULL'; 118 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; 119 if ($fautoinc) $suffix .= ' AUTO_INCREMENT'; 120 if ($fconstraint) $suffix .= ' '.$fconstraint; 121 return $suffix; 122 } 123 124 /* 125 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] 126 [table_options] [select_statement] 127 create_definition: 128 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] 129 [PRIMARY KEY] [reference_definition] 130 or PRIMARY KEY (index_col_name,...) 131 or KEY [index_name] (index_col_name,...) 132 or INDEX [index_name] (index_col_name,...) 133 or UNIQUE [INDEX] [index_name] (index_col_name,...) 134 or FULLTEXT [INDEX] [index_name] (index_col_name,...) 135 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...) 136 [reference_definition] 137 or CHECK (expr) 138 */ 139 140 /* 141 CREATE [UNIQUE|FULLTEXT] INDEX index_name 142 ON tbl_name (col_name[(length)],... ) 143 */ 144 145 function _IndexSQL($idxname, $tabname, $flds, $idxoptions) 146 { 147 $sql = array(); 148 149 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { 150 if ($this->alterTableAddIndex) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname"; 151 else $sql[] = sprintf($this->dropIndex, $idxname, $tabname); 152 153 if ( isset($idxoptions['DROP']) ) 154 return $sql; 155 } 156 157 if ( empty ($flds) ) { 158 return $sql; 159 } 160 161 if (isset($idxoptions['FULLTEXT'])) { 162 $unique = ' FULLTEXT'; 163 } elseif (isset($idxoptions['UNIQUE'])) { 164 $unique = ' UNIQUE'; 165 } else { 166 $unique = ''; 167 } 168 169 if ( is_array($flds) ) $flds = implode(', ',$flds); 170 171 if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname "; 172 else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname; 173 174 $s .= ' (' . $flds . ')'; 175 176 if ( isset($idxoptions[$this->upperName]) ) 177 $s .= $idxoptions[$this->upperName]; 178 179 $sql[] = $s; 180 181 return $sql; 182 } 183 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body