- Timestamp:
- 2013/08/02 13:22:57 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/mysql.php
r20764 r23022 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysql.php ,v 1.80 2008/03/26 21:15:37 quipo Exp$45 // $Id: mysql.php 327310 2012-08-27 15:16:18Z danielc $ 46 46 // 47 47 … … 70 70 function getTableFieldDefinition($table_name, $field_name) 71 71 { 72 $db = &$this->getDBInstance();73 if ( PEAR::isError($db)) {72 $db = $this->getDBInstance(); 73 if (MDB2::isError($db)) { 74 74 return $db; 75 75 } 76 76 77 77 $result = $db->loadModule('Datatype', null, true); 78 if ( PEAR::isError($result)) {78 if (MDB2::isError($result)) { 79 79 return $result; 80 80 } … … 85 85 $query = "SHOW FULL COLUMNS FROM $table LIKE ".$db->quote($field_name); 86 86 $columns = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC); 87 if ( PEAR::isError($columns)) {87 if (MDB2::isError($columns)) { 88 88 return $columns; 89 89 } … … 103 103 if ($field_name == $column['name']) { 104 104 $mapped_datatype = $db->datatype->mapNativeDatatype($column); 105 if ( PEAR::isError($mapped_datatype)) {105 if (MDB2::isError($mapped_datatype)) { 106 106 return $mapped_datatype; 107 107 } … … 114 114 if (array_key_exists('default', $column)) { 115 115 $default = $column['default']; 116 if ( is_null($default) && $notnull) {116 if ((null === $default) && $notnull) { 117 117 $default = ''; 118 118 } 119 119 } 120 $definition[0] = array( 121 'notnull' => $notnull, 122 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 123 ); 120 124 $autoincrement = false; 121 if (!empty($column['extra']) && $column['extra'] == 'auto_increment') { 122 $autoincrement = true; 125 if (!empty($column['extra'])) { 126 if ($column['extra'] == 'auto_increment') { 127 $autoincrement = true; 128 } else { 129 $definition[0]['extra'] = $column['extra']; 130 } 123 131 } 124 132 $collate = null; … … 128 136 } 129 137 130 $definition[0] = array( 131 'notnull' => $notnull, 132 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 133 ); 134 if (!is_null($length)) { 138 if (null !== $length) { 135 139 $definition[0]['length'] = $length; 136 140 } 137 if ( !is_null($unsigned)) {141 if (null !== $unsigned) { 138 142 $definition[0]['unsigned'] = $unsigned; 139 143 } 140 if ( !is_null($fixed)) {144 if (null !== $fixed) { 141 145 $definition[0]['fixed'] = $fixed; 142 146 } … … 147 151 $definition[0]['autoincrement'] = $autoincrement; 148 152 } 149 if ( !is_null($collate)) {153 if (null !== $collate) { 150 154 $definition[0]['collate'] = $collate; 151 155 $definition[0]['charset'] = $charset; … … 182 186 function getTableIndexDefinition($table_name, $index_name) 183 187 { 184 $db = &$this->getDBInstance();185 if ( PEAR::isError($db)) {188 $db = $this->getDBInstance(); 189 if (MDB2::isError($db)) { 186 190 return $db; 187 191 } … … 193 197 $index_name_mdb2 = $db->getIndexName($index_name); 194 198 $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); 195 if (! PEAR::isError($result) && !is_null($result)) {199 if (!MDB2::isError($result) && (null !== $result)) { 196 200 // apply 'idxname_format' only if the query succeeded, otherwise 197 201 // fallback to the given $index_name, without transformation … … 199 203 } 200 204 $result = $db->query(sprintf($query, $db->quote($index_name))); 201 if ( PEAR::isError($result)) {205 if (MDB2::isError($result)) { 202 206 return $result; 203 207 } … … 257 261 function getTableConstraintDefinition($table_name, $constraint_name) 258 262 { 259 $db = &$this->getDBInstance();260 if ( PEAR::isError($db)) {263 $db = $this->getDBInstance(); 264 if (MDB2::isError($db)) { 261 265 return $db; 262 266 } … … 270 274 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 271 275 $result = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2))); 272 if (! PEAR::isError($result) && !is_null($result)) {276 if (!MDB2::isError($result) && (null !== $result)) { 273 277 // apply 'idxname_format' only if the query succeeded, otherwise 274 278 // fallback to the given $index_name, without transformation … … 277 281 } 278 282 $result = $db->query(sprintf($query, $db->quote($constraint_name))); 279 if ( PEAR::isError($result)) {283 if (MDB2::isError($result)) { 280 284 return $result; 281 285 } … … 357 361 function _getTableFKConstraintDefinition($table, $constraint_name, $definition) 358 362 { 359 $db = &$this->getDBInstance();360 if ( PEAR::isError($db)) {363 $db = $this->getDBInstance(); 364 if (MDB2::isError($db)) { 361 365 return $db; 362 366 } 367 //Use INFORMATION_SCHEMA instead? 368 //SELECT * 369 // FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS 370 // WHERE CONSTRAINT_SCHEMA = '$dbname' 371 // AND TABLE_NAME = '$table' 372 // AND CONSTRAINT_NAME = '$constraint_name'; 363 373 $query = 'SHOW CREATE TABLE '. $db->escape($table); 364 374 $constraint = $db->queryOne($query, 'text', 1); 365 if (! PEAR::isError($constraint) && !empty($constraint)) {375 if (!MDB2::isError($constraint) && !empty($constraint)) { 366 376 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 367 377 if ($db->options['field_case'] == CASE_LOWER) { … … 373 383 $constraint_name_original = $constraint_name; 374 384 $constraint_name = $db->getIndexName($constraint_name); 375 $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';385 $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i'; 376 386 if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 377 387 //fallback to original constraint name 378 $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';388 $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i'; 379 389 } 380 390 if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) { … … 398 408 ); 399 409 } 400 $definition['on update'] = 'NO ACTION';401 $definition['on delete'] = 'NO ACTION';410 $definition['ondelete'] = empty($matches[4]) ? 'RESTRICT' : strtoupper($matches[4]); 411 $definition['onupdate'] = empty($matches[5]) ? 'RESTRICT' : strtoupper($matches[5]); 402 412 $definition['match'] = 'SIMPLE'; 403 413 return $definition; … … 425 435 function getTriggerDefinition($trigger) 426 436 { 427 $db = &$this->getDBInstance();428 if ( PEAR::isError($db)) {437 $db = $this->getDBInstance(); 438 if (MDB2::isError($db)) { 429 439 return $db; 430 440 } … … 445 455 ); 446 456 $def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC); 447 if ( PEAR::isError($def)) {457 if (MDB2::isError($def)) { 448 458 return $def; 449 459 } … … 477 487 } 478 488 479 $db = &$this->getDBInstance();480 if ( PEAR::isError($db)) {489 $db = $this->getDBInstance(); 490 if (MDB2::isError($db)) { 481 491 return $db; 482 492 } … … 507 517 for ($i = 0; $i < $count; $i++) { 508 518 $res[$i] = array( 509 'table' => $case_func(@mysql_field_table($resource, $i)),510 'name' => $case_func(@mysql_field_name($resource, $i)),511 'type' => @mysql_field_type($resource, $i),512 'length' => @mysql_field_len($resource, $i),513 'flags' => @mysql_field_flags($resource, $i),519 'table' => $case_func(@mysql_field_table($resource, $i)), 520 'name' => $case_func(@mysql_field_name($resource, $i)), 521 'type' => @mysql_field_type($resource, $i), 522 'length' => @mysql_field_len($resource, $i), 523 'flags' => @mysql_field_flags($resource, $i), 514 524 ); 515 525 if ($res[$i]['type'] == 'string') { … … 519 529 } 520 530 $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]); 521 if ( PEAR::isError($mdb2type_info)) {531 if (MDB2::isError($mdb2type_info)) { 522 532 return $mdb2type_info; 523 533 }
Note: See TracChangeset
for help on using the changeset viewer.
