Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
1 <?php 2 3 /** 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. 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 public $blobAllowsNotNull = true; 28 29 function MetaType($t,$len=-1,$fieldobj=false) 30 { 31 32 if (is_object($t)) { 33 $fieldobj = $t; 34 $t = $fieldobj->type; 35 $len = $fieldobj->max_length; 36 } 37 $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment; 38 39 $len = -1; // mysql max_length is not accurate 40 switch (strtoupper($t)) { 41 case 'STRING': 42 case 'CHAR': 43 case 'VARCHAR': 44 case 'TINYBLOB': 45 case 'TINYTEXT': 46 case 'ENUM': 47 case 'SET': 48 if ($len <= $this->blobSize) return 'C'; 49 50 case 'TEXT': 51 case 'LONGTEXT': 52 case 'MEDIUMTEXT': 53 return 'X'; 54 55 // php_mysql extension always returns 'blob' even if 'text' 56 // so we have to check whether binary... 57 case 'IMAGE': 58 case 'LONGBLOB': 59 case 'BLOB': 60 case 'MEDIUMBLOB': 61 return !empty($fieldobj->binary) ? 'B' : 'X'; 62 63 case 'YEAR': 64 case 'DATE': return 'D'; 65 66 case 'TIME': 67 case 'DATETIME': 68 case 'TIMESTAMP': return 'T'; 69 70 case 'FLOAT': 71 case 'DOUBLE': 72 return 'F'; 73 74 case 'INT': 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; 81 } 82 } 83 84 function ActualType($meta) 85 { 86 switch(strtoupper($meta)) { 87 case 'C': return 'VARCHAR'; 88 case 'XL':return 'LONGTEXT'; 89 case 'X': return 'TEXT'; 90 91 case 'C2': return 'VARCHAR'; 92 case 'X2': return 'LONGTEXT'; 93 94 case 'B': return 'LONGBLOB'; 95 96 case 'D': return 'DATE'; 97 case 'TS': 98 case 'T': return 'DATETIME'; 99 case 'L': return 'TINYINT'; 100 101 case 'R': 102 case 'I4': 103 case 'I': return 'INTEGER'; 104 case 'I1': return 'TINYINT'; 105 case 'I2': return 'SMALLINT'; 106 case 'I8': return 'BIGINT'; 107 108 case 'F': return 'DOUBLE'; 109 case 'N': return 'NUMERIC'; 110 default: 111 return $meta; 112 } 113 } 114 115 // return string must begin with space 116 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) 117 { 118 $suffix = ''; 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; 124 return $suffix; 125 } 126 127 /* 128 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] 129 [table_options] [select_statement] 130 create_definition: 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] 140 or CHECK (expr) 141 */ 142 143 /* 144 CREATE [UNIQUE|FULLTEXT] INDEX index_name 145 ON tbl_name (col_name[(length)],... ) 146 */ 147 148 function _IndexSQL($idxname, $tabname, $flds, $idxoptions) 149 { 150 $sql = array(); 151 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); 155 156 if ( isset($idxoptions['DROP']) ) 157 return $sql; 158 } 159 160 if ( empty ($flds) ) { 161 return $sql; 162 } 163 164 if (isset($idxoptions['FULLTEXT'])) { 165 $unique = ' FULLTEXT'; 166 } elseif (isset($idxoptions['UNIQUE'])) { 167 $unique = ' UNIQUE'; 168 } else { 169 $unique = ''; 170 } 171 172 if ( is_array($flds) ) $flds = implode(', ',$flds); 173 174 if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname "; 175 else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname; 176 177 $s .= ' (' . $flds . ')'; 178 179 if ( isset($idxoptions[$this->upperName]) ) 180 $s .= $idxoptions[$this->upperName]; 181 182 $sql[] = $s; 183 184 return $sql; 185 } 186 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body