- 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/Common.php
r20119 r23022 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Common.php ,v 1.139 2008/12/04 11:50:42 afz Exp$45 // $Id: Common.php 328137 2012-10-25 02:26:35Z danielc $ 46 46 47 47 require_once 'MDB2/LOB.php'; … … 101 101 { 102 102 $types = $this->valid_default_values; 103 $db = &$this->getDBInstance();104 if ( PEAR::isError($db)) {103 $db = $this->getDBInstance(); 104 if (MDB2::isError($db)) { 105 105 return $db; 106 106 } … … 146 146 foreach ($types as $key => $type) { 147 147 if (!isset($this->valid_default_values[$type])) { 148 $db = &$this->getDBInstance();149 if ( PEAR::isError($db)) {148 $db = $this->getDBInstance(); 149 if (MDB2::isError($db)) { 150 150 return $db; 151 151 } … … 210 210 } 211 211 212 $db = &$this->getDBInstance();213 if ( PEAR::isError($db)) {212 $db = $this->getDBInstance(); 213 if (MDB2::isError($db)) { 214 214 return $db; 215 215 } … … 233 233 function convertResult($value, $type, $rtrim = true) 234 234 { 235 if ( is_null($value)) {235 if (null === $value) { 236 236 return null; 237 237 } 238 $db = &$this->getDBInstance();239 if ( PEAR::isError($db)) {238 $db = $this->getDBInstance(); 239 if (MDB2::isError($db)) { 240 240 return $db; 241 241 } … … 264 264 function convertResultRow($types, $row, $rtrim = true) 265 265 { 266 $types = $this->_sortResultFieldTypes(array_keys($row), $types); 266 //$types = $this->_sortResultFieldTypes(array_keys($row), $types); 267 $keys = array_keys($row); 268 if (is_int($keys[0])) { 269 $types = $this->_sortResultFieldTypes($keys, $types); 270 } 267 271 foreach ($row as $key => $value) { 268 272 if (empty($types[$key])) { … … 270 274 } 271 275 $value = $this->convertResult($row[$key], $types[$key], $rtrim); 272 if ( PEAR::isError($value)) {276 if (MDB2::isError($value)) { 273 277 return $value; 274 278 } … … 314 318 reset($types); 315 319 foreach (array_keys($sorted_types) as $k) { 316 if ( is_null($sorted_types[$k])) {320 if (null === $sorted_types[$k]) { 317 321 $sorted_types[$k] = current($types); 318 322 next($types); … … 339 343 function getDeclaration($type, $name, $field) 340 344 { 341 $db = &$this->getDBInstance();342 if ( PEAR::isError($db)) {345 $db = $this->getDBInstance(); 346 if (MDB2::isError($db)) { 343 347 return $db; 344 348 } … … 388 392 function getTypeDeclaration($field) 389 393 { 390 $db = &$this->getDBInstance();391 if ( PEAR::isError($db)) {394 $db = $this->getDBInstance(); 395 if (MDB2::isError($db)) { 392 396 return $db; 393 397 } … … 454 458 function _getDeclaration($name, $field) 455 459 { 456 $db = &$this->getDBInstance();457 if ( PEAR::isError($db)) {460 $db = $this->getDBInstance(); 461 if (MDB2::isError($db)) { 458 462 return $db; 459 463 } … … 461 465 $name = $db->quoteIdentifier($name, true); 462 466 $declaration_options = $db->datatype->_getDeclarationOptions($field); 463 if ( PEAR::isError($declaration_options)) {467 if (MDB2::isError($declaration_options)) { 464 468 return $declaration_options; 465 469 } … … 502 506 if (array_key_exists('default', $field)) { 503 507 if ($field['default'] === '') { 504 $db = &$this->getDBInstance();505 if ( PEAR::isError($db)) {508 $db = $this->getDBInstance(); 509 if (MDB2::isError($db)) { 506 510 return $db; 507 511 } 508 512 $valid_default_values = $this->getValidTypes(); 509 513 $field['default'] = $valid_default_values[$field['type']]; 510 if ($field['default'] === '' && ($db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) {514 if ($field['default'] === '' && ($db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) { 511 515 $field['default'] = ' '; 512 516 } 513 517 } 514 if ( !is_null($field['default'])) {518 if (null !== $field['default']) { 515 519 $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']); 516 520 } … … 525 529 // }}} 526 530 // {{{ _getCharsetFieldDeclaration() 527 531 528 532 /** 529 533 * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET … … 584 588 { 585 589 if (!empty($field['unsigned'])) { 586 $db = &$this->getDBInstance();587 if ( PEAR::isError($db)) {590 $db = $this->getDBInstance(); 591 if (MDB2::isError($db)) { 588 592 return $db; 589 593 } … … 652 656 function _getCLOBDeclaration($name, $field) 653 657 { 654 $db = &$this->getDBInstance();655 if ( PEAR::isError($db)) {658 $db = $this->getDBInstance(); 659 if (MDB2::isError($db)) { 656 660 return $db; 657 661 } … … 688 692 function _getBLOBDeclaration($name, $field) 689 693 { 690 $db = &$this->getDBInstance();691 if ( PEAR::isError($db)) {694 $db = $this->getDBInstance(); 695 if (MDB2::isError($db)) { 692 696 return $db; 693 697 } … … 876 880 877 881 if (!method_exists($this, "_compare{$type}Definition")) { 878 $db = &$this->getDBInstance();879 if ( PEAR::isError($db)) {882 $db = $this->getDBInstance(); 883 if (MDB2::isError($db)) { 880 884 return $db; 881 885 } … … 906 910 907 911 $previous_default = array_key_exists('default', $previous) ? $previous['default'] : 908 ($previous_notnull ? '' : null);912 null; 909 913 $default = array_key_exists('default', $current) ? $current['default'] : 910 ($notnull ? '' : null);914 null; 911 915 if ($previous_default !== $default) { 912 916 $change['default'] = true; … … 930 934 { 931 935 $change = array(); 936 $previous_length = !empty($previous['length']) ? $previous['length'] : 4; 937 $length = !empty($current['length']) ? $current['length'] : 4; 938 if ($previous_length != $length) { 939 $change['length'] = $length; 940 } 932 941 $previous_unsigned = !empty($previous['unsigned']) ? $previous['unsigned'] : false; 933 942 $unsigned = !empty($current['unsigned']) ? $current['unsigned'] : false; … … 1115 1124 function quote($value, $type = null, $quote = true, $escape_wildcards = false) 1116 1125 { 1117 $db = &$this->getDBInstance();1118 if ( PEAR::isError($db)) {1126 $db = $this->getDBInstance(); 1127 if (MDB2::isError($db)) { 1119 1128 return $db; 1120 1129 } 1121 1130 1122 if ( is_null($value)1131 if ((null === $value) 1123 1132 || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) 1124 1133 ) { … … 1129 1138 } 1130 1139 1131 if ( is_null($type)) {1140 if (null === $type) { 1132 1141 switch (gettype($value)) { 1133 1142 case 'integer': … … 1219 1228 } 1220 1229 1221 $db = &$this->getDBInstance();1222 if ( PEAR::isError($db)) {1230 $db = $this->getDBInstance(); 1231 if (MDB2::isError($db)) { 1223 1232 return $db; 1224 1233 } 1225 1234 1226 1235 $value = $db->escape($value, $escape_wildcards); 1227 if ( PEAR::isError($value)) {1236 if (MDB2::isError($value)) { 1228 1237 return $value; 1229 1238 } … … 1248 1257 if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) { 1249 1258 $close = true; 1250 if ( $match[1]== 'file://') {1259 if (strtolower($match[1]) == 'file://') { 1251 1260 $value = $match[2]; 1252 1261 } … … 1255 1264 1256 1265 if (is_resource($value)) { 1257 $db = &$this->getDBInstance();1258 if ( PEAR::isError($db)) {1266 $db = $this->getDBInstance(); 1267 if (MDB2::isError($db)) { 1259 1268 return $db; 1260 1269 } … … 1289 1298 function _quoteLOB($value, $quote, $escape_wildcards) 1290 1299 { 1291 $value = $this->_readFile($value); 1292 if (PEAR::isError($value)) { 1293 return $value; 1300 $db = $this->getDBInstance(); 1301 if (MDB2::isError($db)) { 1302 return $db; 1303 } 1304 if ($db->options['lob_allow_url_include']) { 1305 $value = $this->_readFile($value); 1306 if (MDB2::isError($value)) { 1307 return $value; 1308 } 1294 1309 } 1295 1310 return $this->_quoteText($value, $quote, $escape_wildcards); … … 1370 1385 { 1371 1386 if ($value === 'CURRENT_DATE') { 1372 $db = &$this->getDBInstance();1373 if ( PEAR::isError($db)) {1387 $db = $this->getDBInstance(); 1388 if (MDB2::isError($db)) { 1374 1389 return $db; 1375 1390 } 1376 if (isset($db->function) && is_ a($db->function, 'MDB2_Driver_Function_Common')) {1391 if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) { 1377 1392 return $db->function->now('date'); 1378 1393 } … … 1399 1414 { 1400 1415 if ($value === 'CURRENT_TIMESTAMP') { 1401 $db = &$this->getDBInstance();1402 if ( PEAR::isError($db)) {1416 $db = $this->getDBInstance(); 1417 if (MDB2::isError($db)) { 1403 1418 return $db; 1404 1419 } 1405 if (isset($db->function) && is_ a($db->function, 'MDB2_Driver_Function_Common')) {1420 if (isset($db->function) && is_object($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) { 1406 1421 return $db->function->now('timestamp'); 1407 1422 } … … 1428 1443 { 1429 1444 if ($value === 'CURRENT_TIME') { 1430 $db = &$this->getDBInstance();1431 if ( PEAR::isError($db)) {1445 $db = $this->getDBInstance(); 1446 if (MDB2::isError($db)) { 1432 1447 return $db; 1433 1448 } 1434 if (isset($db->function) && is_ a($db->function, 'MDB2_Driver_Function_Common')) {1449 if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) { 1435 1450 return $db->function->now('time'); 1436 1451 } … … 1518 1533 function writeLOBToFile($lob, $file) 1519 1534 { 1520 $db = &$this->getDBInstance();1521 if ( PEAR::isError($db)) {1535 $db = $this->getDBInstance(); 1536 if (MDB2::isError($db)) { 1522 1537 return $db; 1523 1538 } … … 1555 1570 function _retrieveLOB(&$lob) 1556 1571 { 1557 if ( is_null($lob['value'])) {1572 if (null === $lob['value']) { 1558 1573 $lob['value'] = $lob['resource']; 1559 1574 } … … 1682 1697 function matchPattern($pattern, $operator = null, $field = null) 1683 1698 { 1684 $db = &$this->getDBInstance();1685 if ( PEAR::isError($db)) {1699 $db = $this->getDBInstance(); 1700 if (MDB2::isError($db)) { 1686 1701 return $db; 1687 1702 } 1688 1703 1689 1704 $match = ''; 1690 if ( !is_null($operator)) {1705 if (null !== $operator) { 1691 1706 $operator = strtoupper($operator); 1692 1707 switch ($operator) { 1693 1708 // case insensitive 1694 1709 case 'ILIKE': 1695 if ( is_null($field)) {1710 if (null === $field) { 1696 1711 return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 1697 1712 'case insensitive LIKE matching requires passing the field name', __FUNCTION__); … … 1700 1715 $match = $db->function->lower($field).' LIKE '; 1701 1716 break; 1717 case 'NOT ILIKE': 1718 if (null === $field) { 1719 return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 1720 'case insensitive NOT ILIKE matching requires passing the field name', __FUNCTION__); 1721 } 1722 $db->loadModule('Function', null, true); 1723 $match = $db->function->lower($field).' NOT LIKE '; 1724 break; 1702 1725 // case sensitive 1703 1726 case 'LIKE': 1704 $match = is_null($field) ? 'LIKE ' : $field.' LIKE '; 1727 $match = (null === $field) ? 'LIKE ' : ($field.' LIKE '); 1728 break; 1729 case 'NOT LIKE': 1730 $match = (null === $field) ? 'NOT LIKE ' : ($field.' NOT LIKE '); 1705 1731 break; 1706 1732 default: … … 1714 1740 $match.= $value; 1715 1741 } else { 1716 if ($operator === 'ILIKE') {1717 $value = strtolower($value);1718 }1719 1742 $escaped = $db->escape($value); 1720 if ( PEAR::isError($escaped)) {1743 if (MDB2::isError($escaped)) { 1721 1744 return $escaped; 1722 1745 } … … 1756 1779 function mapNativeDatatype($field) 1757 1780 { 1758 $db = &$this->getDBInstance();1759 if ( PEAR::isError($db)) {1781 $db = $this->getDBInstance(); 1782 if (MDB2::isError($db)) { 1760 1783 return $db; 1761 1784 } … … 1785 1808 function _mapNativeDatatype($field) 1786 1809 { 1787 $db = &$this->getDBInstance();1788 if ( PEAR::isError($db)) {1810 $db = $this->getDBInstance(); 1811 if (MDB2::isError($db)) { 1789 1812 return $db; 1790 1813 } … … 1806 1829 function mapPrepareDatatype($type) 1807 1830 { 1808 $db = &$this->getDBInstance();1809 if ( PEAR::isError($db)) {1831 $db = $this->getDBInstance(); 1832 if (MDB2::isError($db)) { 1810 1833 return $db; 1811 1834 }
Note: See TracChangeset
for help on using the changeset viewer.