- Timestamp:
- 2013/08/02 13:22:57 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/mysql.php
r20764 r23022 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mysql.php ,v 1.65 2008/02/22 19:23:49 quipo Exp$46 // $Id: mysql.php 327310 2012-08-27 15:16:18Z danielc $ 47 47 // 48 48 … … 90 90 91 91 // }}} 92 // {{{ getDeclaration() 93 94 /** 95 * Obtain DBMS specific SQL code portion needed to declare 96 * of the given type 97 * 98 * @param string $type type to which the value should be converted to 99 * @param string $name name the field to be declared. 100 * @param string $field definition of the field 101 * 102 * @return string DBMS-specific SQL code portion that should be used to 103 * declare the specified field. 104 * @access public 105 */ 106 function getDeclaration($type, $name, $field) 107 { 108 // MySQL DDL syntax forbids combining NOT NULL with DEFAULT NULL. 109 // To get a default of NULL for NOT NULL columns, omit it. 110 if ( isset($field['notnull']) 111 && !empty($field['notnull']) 112 && array_key_exists('default', $field) // do not use isset() here! 113 && null === $field['default'] 114 ) { 115 unset($field['default']); 116 } 117 return parent::getDeclaration($type, $name, $field); 118 } 119 120 // }}} 92 121 // {{{ getTypeDeclaration() 93 122 … … 117 146 function getTypeDeclaration($field) 118 147 { 119 $db = &$this->getDBInstance();120 if ( PEAR::isError($db)) {148 $db = $this->getDBInstance(); 149 if (MDB2::isError($db)) { 121 150 return $db; 122 151 } … … 180 209 return 'DATETIME'; 181 210 case 'float': 182 return 'DOUBLE'; 211 $l = ''; 212 if (!empty($field['length'])) { 213 $l = '(' . $field['length']; 214 if (!empty($field['scale'])) { 215 $l .= ',' . $field['scale']; 216 } 217 $l .= ')'; 218 } 219 return 'DOUBLE' . $l; 183 220 case 'decimal': 184 221 $length = !empty($field['length']) ? $field['length'] : 18; … … 220 257 function _getIntegerDeclaration($name, $field) 221 258 { 222 $db = &$this->getDBInstance();223 if ( PEAR::isError($db)) {259 $db = $this->getDBInstance(); 260 if (MDB2::isError($db)) { 224 261 return $db; 225 262 } … … 237 274 $notnull = empty($field['notnull']) ? '' : ' NOT NULL'; 238 275 $unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED'; 276 if (empty($default) && empty($notnull)) { 277 $default = ' DEFAULT NULL'; 278 } 239 279 $name = $db->quoteIdentifier($name, true); 240 280 return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc; … … 309 349 function _getDecimalDeclaration($name, $field) 310 350 { 311 $db = &$this->getDBInstance();312 if ( PEAR::isError($db)) {351 $db = $this->getDBInstance(); 352 if (MDB2::isError($db)) { 313 353 return $db; 314 354 } … … 347 387 function matchPattern($pattern, $operator = null, $field = null) 348 388 { 349 $db = &$this->getDBInstance();350 if ( PEAR::isError($db)) {389 $db = $this->getDBInstance(); 390 if (MDB2::isError($db)) { 351 391 return $db; 352 392 } 353 393 354 394 $match = ''; 355 if ( !is_null($operator)) {356 $field = is_null($field) ? '' : $field.' ';395 if (null !== $operator) { 396 $field = (null === $field) ? '' : $field.' '; 357 397 $operator = strtoupper($operator); 358 398 switch ($operator) { … … 361 401 $match = $field.'LIKE '; 362 402 break; 403 case 'NOT ILIKE': 404 $match = $field.'NOT LIKE '; 405 break; 363 406 // case sensitive 364 407 case 'LIKE': 365 408 $match = $field.'LIKE BINARY '; 409 break; 410 case 'NOT LIKE': 411 $match = $field.'NOT LIKE BINARY '; 366 412 break; 367 413 default: … … 505 551 $type[] = 'float'; 506 552 $unsigned = preg_match('/ unsigned/i', $field['type']); 553 if ($decimal !== false) { 554 $length = $length.','.$decimal; 555 } 507 556 break; 508 557 case 'unknown': … … 532 581 break; 533 582 default: 534 $db = &$this->getDBInstance();535 if ( PEAR::isError($db)) {583 $db = $this->getDBInstance(); 584 if (MDB2::isError($db)) { 536 585 return $db; 537 586 }
Note: See TracChangeset
for help on using the changeset viewer.