- Timestamp:
- 2013/08/02 13:22:57 (13 years ago)
- Location:
- branches/version-2_13-dev/data/module/MDB2/Driver/Reverse
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/Common.php
r20764 r23022 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Common.php ,v 1.43 2009/01/14 15:01:21 quipo Exp$45 // $Id: Common.php 327310 2012-08-27 15:16:18Z danielc $ 46 46 // 47 47 … … 108 108 function getTableFieldDefinition($table, $field) 109 109 { 110 $db = &$this->getDBInstance();111 if ( PEAR::isError($db)) {110 $db = $this->getDBInstance(); 111 if (MDB2::isError($db)) { 112 112 return $db; 113 113 } … … 142 142 function getTableIndexDefinition($table, $index) 143 143 { 144 $db = &$this->getDBInstance();145 if ( PEAR::isError($db)) {144 $db = $this->getDBInstance(); 145 if (MDB2::isError($db)) { 146 146 return $db; 147 147 } … … 194 194 function getTableConstraintDefinition($table, $index) 195 195 { 196 $db = &$this->getDBInstance();197 if ( PEAR::isError($db)) {196 $db = $this->getDBInstance(); 197 if (MDB2::isError($db)) { 198 198 return $db; 199 199 } … … 221 221 function getSequenceDefinition($sequence) 222 222 { 223 $db = &$this->getDBInstance();224 if ( PEAR::isError($db)) {223 $db = $this->getDBInstance(); 224 if (MDB2::isError($db)) { 225 225 return $db; 226 226 } 227 227 228 228 $start = $db->currId($sequence); 229 if ( PEAR::isError($start)) {229 if (MDB2::isError($start)) { 230 230 return $start; 231 231 } … … 274 274 function getTriggerDefinition($trigger) 275 275 { 276 $db = &$this->getDBInstance();277 if ( PEAR::isError($db)) {276 $db = $this->getDBInstance(); 277 if (MDB2::isError($db)) { 278 278 return $db; 279 279 } … … 408 408 function tableInfo($result, $mode = null) 409 409 { 410 $db = &$this->getDBInstance();411 if ( PEAR::isError($db)) {410 $db = $this->getDBInstance(); 411 if (MDB2::isError($db)) { 412 412 return $db; 413 413 } … … 420 420 $db->loadModule('Manager', null, true); 421 421 $fields = $db->manager->listTableFields($result); 422 if ( PEAR::isError($fields)) {422 if (MDB2::isError($fields)) { 423 423 return $fields; 424 424 } … … 430 430 431 431 $indexes = $db->manager->listTableIndexes($result); 432 if ( PEAR::isError($indexes)) {432 if (MDB2::isError($indexes)) { 433 433 $db->setOption('idxname_format', $idxname_format); 434 434 return $indexes; … … 437 437 foreach ($indexes as $index) { 438 438 $definition = $this->getTableIndexDefinition($result, $index); 439 if ( PEAR::isError($definition)) {439 if (MDB2::isError($definition)) { 440 440 $db->setOption('idxname_format', $idxname_format); 441 441 return $definition; … … 449 449 450 450 $constraints = $db->manager->listTableConstraints($result); 451 if ( PEAR::isError($constraints)) {451 if (MDB2::isError($constraints)) { 452 452 return $constraints; 453 453 } … … 455 455 foreach ($constraints as $constraint) { 456 456 $definition = $this->getTableConstraintDefinition($result, $constraint); 457 if ( PEAR::isError($definition)) {457 if (MDB2::isError($definition)) { 458 458 $db->setOption('idxname_format', $idxname_format); 459 459 return $definition; … … 479 479 foreach ($fields as $i => $field) { 480 480 $definition = $this->getTableFieldDefinition($result, $field); 481 if ( PEAR::isError($definition)) {481 if (MDB2::isError($definition)) { 482 482 $db->setOption('idxname_format', $idxname_format); 483 483 return $definition; -
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 } -
branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/pgsql.php
r20764 r23022 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: pgsql.php ,v 1.75 2008/08/22 16:36:20 quipo Exp$46 // $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $ 47 47 48 48 require_once 'MDB2/Driver/Reverse/Common.php'; … … 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 } … … 123 123 ORDER BY a.attnum"; 124 124 $column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC); 125 if ( PEAR::isError($column)) {125 if (MDB2::isError($column)) { 126 126 return $column; 127 127 } … … 134 134 $column = array_change_key_case($column, CASE_LOWER); 135 135 $mapped_datatype = $db->datatype->mapNativeDatatype($column); 136 if ( PEAR::isError($mapped_datatype)) {136 if (MDB2::isError($mapped_datatype)) { 137 137 return $mapped_datatype; 138 138 } … … 144 144 $default = null; 145 145 if ($column['atthasdef'] === 't' 146 && strpos($column['default'], 'NULL') !== 0 146 147 && !preg_match("/nextval\('([^']+)'/", $column['default']) 147 148 ) { 148 149 $pattern = '/^\'(.*)\'::[\w ]+$/i'; 149 150 $default = $column['default'];#substr($column['adsrc'], 1, -1); 150 if ( is_null($default) && $notnull) {151 if ((null === $default) && $notnull) { 151 152 $default = ''; 152 153 } elseif (!empty($default) && preg_match($pattern, $default)) { … … 160 161 } 161 162 $definition[0] = array('notnull' => $notnull, 'nativetype' => $column['type']); 162 if ( !is_null($length)) {163 if (null !== $length) { 163 164 $definition[0]['length'] = $length; 164 165 } 165 if ( !is_null($unsigned)) {166 if (null !== $unsigned) { 166 167 $definition[0]['unsigned'] = $unsigned; 167 168 } 168 if ( !is_null($fixed)) {169 if (null !== $fixed) { 169 170 $definition[0]['fixed'] = $fixed; 170 171 } … … 199 200 function getTableIndexDefinition($table_name, $index_name) 200 201 { 201 $db = &$this->getDBInstance();202 if ( PEAR::isError($db)) {202 $db = $this->getDBInstance(); 203 if (MDB2::isError($db)) { 203 204 return $db; 204 205 } … … 212 213 $index_name_mdb2 = $db->getIndexName($index_name); 213 214 $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 214 if ( PEAR::isError($row) || empty($row)) {215 if (MDB2::isError($row) || empty($row)) { 215 216 // fallback to the given $index_name, without transformation 216 217 $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC); 217 218 } 218 if ( PEAR::isError($row)) {219 if (MDB2::isError($row)) { 219 220 return $row; 220 221 } … … 257 258 function getTableConstraintDefinition($table_name, $constraint_name) 258 259 { 259 $db = &$this->getDBInstance();260 if ( PEAR::isError($db)) {260 $db = $this->getDBInstance(); 261 if (MDB2::isError($db)) { 261 262 return $db; 262 263 } … … 303 304 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 304 305 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 305 if ( PEAR::isError($row) || empty($row)) {306 if (MDB2::isError($row) || empty($row)) { 306 307 // fallback to the given $index_name, without transformation 307 308 $constraint_name_mdb2 = $constraint_name; 308 309 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 309 310 } 310 if ( PEAR::isError($row)) {311 if (MDB2::isError($row)) { 311 312 return $row; 312 313 } … … 333 334 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 334 335 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 335 if ( PEAR::isError($row) || empty($row)) {336 if (MDB2::isError($row) || empty($row)) { 336 337 // fallback to the given $index_name, without transformation 337 338 $constraint_name_mdb2 = $constraint_name; 338 339 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 339 340 } 340 if ( PEAR::isError($row)) {341 if (MDB2::isError($row)) { 341 342 return $row; 342 343 } … … 388 389 AND t.relname = ' . $db->quote($table, 'text'); 389 390 $fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null); 390 if ( PEAR::isError($fields)) {391 if (MDB2::isError($fields)) { 391 392 return $fields; 392 393 } … … 407 408 AND t.relname = ' . $db->quote($definition['references']['table'], 'text'); 408 409 $foreign_fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null); 409 if ( PEAR::isError($foreign_fields)) {410 if (MDB2::isError($foreign_fields)) { 410 411 return $foreign_fields; 411 412 } … … 444 445 function getTriggerDefinition($trigger) 445 446 { 446 $db = &$this->getDBInstance();447 if ( PEAR::isError($db)) {447 $db = $this->getDBInstance(); 448 if (MDB2::isError($db)) { 448 449 return $db; 449 450 } … … 518 519 } 519 520 520 $db = &$this->getDBInstance();521 if ( PEAR::isError($db)) {521 $db = $this->getDBInstance(); 522 if (MDB2::isError($db)) { 522 523 return $db; 523 524 } … … 556 557 ); 557 558 $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]); 558 if ( PEAR::isError($mdb2type_info)) {559 if (MDB2::isError($mdb2type_info)) { 559 560 return $mdb2type_info; 560 561 }
Note: See TracChangeset
for help on using the changeset viewer.
