Changeset 3227 in subversion
- Timestamp:
- Jan 26, 2010 8:45:16 AM (3 years ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 6 added
- 44 edited
-
CHANGELOG (modified) (1 diff)
-
config/db.inc.php.dist (modified) (1 diff)
-
program/include/rcmail.php (modified) (1 diff)
-
program/include/rcube_mdb2.php (modified) (3 diffs)
-
program/lib/MDB2.php (modified) (46 diffs)
-
program/lib/MDB2/Date.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Datatype/Common.php (modified) (11 diffs)
-
program/lib/MDB2/Driver/Datatype/mssql.php (modified) (5 diffs)
-
program/lib/MDB2/Driver/Datatype/mysql.php (modified) (3 diffs)
-
program/lib/MDB2/Driver/Datatype/mysqli.php (modified) (3 diffs)
-
program/lib/MDB2/Driver/Datatype/pgsql.php (modified) (7 diffs)
-
program/lib/MDB2/Driver/Datatype/sqlite.php (modified) (3 diffs)
-
program/lib/MDB2/Driver/Datatype/sqlsrv.php (added)
-
program/lib/MDB2/Driver/Function/Common.php (modified) (2 diffs)
-
program/lib/MDB2/Driver/Function/mssql.php (modified) (2 diffs)
-
program/lib/MDB2/Driver/Function/mysql.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Function/mysqli.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Function/pgsql.php (modified) (2 diffs)
-
program/lib/MDB2/Driver/Function/sqlite.php (modified) (2 diffs)
-
program/lib/MDB2/Driver/Function/sqlsrv.php (added)
-
program/lib/MDB2/Driver/Manager/Common.php (modified) (2 diffs)
-
program/lib/MDB2/Driver/Manager/mssql.php (modified) (4 diffs)
-
program/lib/MDB2/Driver/Manager/mysql.php (modified) (16 diffs)
-
program/lib/MDB2/Driver/Manager/mysqli.php (modified) (16 diffs)
-
program/lib/MDB2/Driver/Manager/pgsql.php (modified) (10 diffs)
-
program/lib/MDB2/Driver/Manager/sqlite.php (modified) (9 diffs)
-
program/lib/MDB2/Driver/Manager/sqlsrv.php (added)
-
program/lib/MDB2/Driver/Native/Common.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Native/mssql.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Native/mysql.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Native/mysqli.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Native/pgsql.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Native/sqlite.php (modified) (1 diff)
-
program/lib/MDB2/Driver/Native/sqlsrv.php (added)
-
program/lib/MDB2/Driver/Reverse/Common.php (modified) (2 diffs)
-
program/lib/MDB2/Driver/Reverse/mssql.php (modified) (5 diffs)
-
program/lib/MDB2/Driver/Reverse/mysql.php (modified) (8 diffs)
-
program/lib/MDB2/Driver/Reverse/mysqli.php (modified) (8 diffs)
-
program/lib/MDB2/Driver/Reverse/pgsql.php (modified) (8 diffs)
-
program/lib/MDB2/Driver/Reverse/sqlite.php (modified) (14 diffs)
-
program/lib/MDB2/Driver/Reverse/sqlsrv.php (added)
-
program/lib/MDB2/Driver/mssql.php (modified) (32 diffs)
-
program/lib/MDB2/Driver/mysql.php (modified) (16 diffs)
-
program/lib/MDB2/Driver/mysqli.php (modified) (34 diffs)
-
program/lib/MDB2/Driver/pgsql.php (modified) (27 diffs)
-
program/lib/MDB2/Driver/sqlite.php (modified) (17 diffs)
-
program/lib/MDB2/Driver/sqlsrv.php (added)
-
program/lib/MDB2/Extended.php (modified) (2 diffs)
-
program/lib/MDB2/Iterator.php (modified) (1 diff)
-
program/lib/MDB2/LOB.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/CHANGELOG
r3226 r3227 2 2 =========================== 3 3 4 - Add support for MDB2's 'sqlsrv' driver (#1486395) 4 5 - Use jQuery-1.4 5 6 - Removed problematic browser-caching of messages -
trunk/roundcubemail/config/db.inc.php.dist
r2947 r3227 18 18 // format is db_provider://user:password@host/database 19 19 // For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php 20 // currently supported db_providers: mysql, mysqli, pgsql, sqlite, mssql 20 // currently supported db_providers: mysql, mysqli, pgsql, sqlite, mssql or sqlsrv 21 21 22 22 $rcmail_config['db_dsnw'] = 'mysql://roundcube:pass@localhost/roundcubemail'; -
trunk/roundcubemail/program/include/rcmail.php
r3212 r3227 1052 1052 1053 1053 $cookie = session_get_cookie_params(); 1054 1054 1055 setcookie($name, $value, $exp, $cookie['path'], $cookie['domain'], 1055 1056 rcube_https_check(), true); -
trunk/roundcubemail/program/include/rcube_mdb2.php
r3212 r3227 107 107 $this->_sqlite_create_database($dbh, $this->sqlite_initials); 108 108 } 109 else if ($this->db_provider!='mssql' )109 else if ($this->db_provider!='mssql' && $this->db_provider!='sqlsrv') 110 110 $dbh->setCharset('utf8'); 111 111 … … 468 468 { 469 469 case 'mssql': 470 case 'sqlsrv': 470 471 return "getdate()"; 471 472 … … 512 513 513 514 case 'mssql': 515 case 'sqlsrv': 514 516 return "DATEDIFF(second, '19700101', $field) + DATEDIFF(second, GETDATE(), GETUTCDATE())"; 515 517 -
trunk/roundcubemail/program/lib/MDB2.php
r3039 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: MDB2.php ,v 1.318 2008/03/08 14:18:38 quipo Exp$46 // $Id: MDB2.php 292663 2009-12-26 18:21:46Z quipo $ 47 47 // 48 48 … … 102 102 define('MDB2_ERROR_INSUFFICIENT_DATA', -35); 103 103 define('MDB2_ERROR_NO_PERMISSION', -36); 104 define('MDB2_ERROR_DISCONNECT_FAILED', -37); 104 105 105 106 // }}} … … 343 344 return $err; 344 345 } 346 if (!MDB2::classExists($class_name)) { 347 $msg = "unable to load class '$class_name' from file '$file_name'"; 348 $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); 349 return $err; 350 } 345 351 } 346 352 return MDB2_OK; … … 404 410 405 411 /** 406 * Create a new MDB2 connection object and connect to the specified412 * Create a new MDB2_Driver_* connection object and connect to the specified 407 413 * database 408 414 * … … 418 424 * ^^ 419 425 * 420 * @param mixed'data source name', see the MDB2::parseDSN421 * method for a description of the dsn format.422 * Can also be specified as an array of the423 * format returned by MDB2::parseDSN.424 * @param arrayAn associative array of option names and425 * their values.426 * 427 * @return mixeda newly created MDB2 connection object, or a MDB2428 * error object on error426 * @param mixed $dsn 'data source name', see the MDB2::parseDSN 427 * method for a description of the dsn format. 428 * Can also be specified as an array of the 429 * format returned by MDB2::parseDSN. 430 * @param array $options An associative array of option names and 431 * their values. 432 * 433 * @return mixed a newly created MDB2 connection object, or a MDB2 434 * error object on error 429 435 * 430 436 * @access public … … 567 573 function apiVersion() 568 574 { 569 return ' 2.5.0b1';575 return '@package_version@'; 570 576 } 571 577 … … 628 634 { 629 635 if (is_a($data, 'MDB2_Error')) { 630 if ( is_null($code)) {636 if (null === $code) { 631 637 return true; 632 638 } elseif (is_string($code)) { … … 768 774 MDB2_ERROR_DEADLOCK => 'deadlock detected', 769 775 MDB2_ERROR_NO_PERMISSION => 'no permission', 776 MDB2_ERROR_DISCONNECT_FAILED => 'disconnect failed', 770 777 ); 771 778 } 772 779 773 if ( is_null($value)) {780 if (null === $value) { 774 781 return $errorMessages; 775 782 } … … 825 832 function parseDSN($dsn) 826 833 { 827 $parsed = array();834 $parsed = $GLOBALS['_MDB2_dsninfo_default']; 828 835 829 836 if (is_array($dsn)) { … … 844 851 } 845 852 846 847 853 // Get phptype and dbsyntax 848 854 // $str => phptype(dbsyntax) … … 856 862 857 863 if (!count($dsn)) { 858 return array_merge($GLOBALS['_MDB2_dsninfo_default'], $parsed);864 return $parsed; 859 865 } 860 866 … … 893 899 //e.g. "scott/tiger@//mymachine:1521/oracle" 894 900 $proto_opts = $dsn; 895 $dsn = substr($proto_opts, strrpos($proto_opts, '/') + 1); 901 $pos = strrpos($proto_opts, '/'); 902 $dsn = substr($proto_opts, $pos + 1); 903 $proto_opts = substr($proto_opts, 0, $pos); 896 904 } elseif (strpos($dsn, '/') !== false) { 897 905 list($proto_opts, $dsn) = explode('/', $dsn, 2); … … 931 939 foreach ($opts as $opt) { 932 940 list($key, $value) = explode('=', $opt); 933 if (! isset($parsed[$key])) {941 if (!array_key_exists($key, $parsed) || false === $parsed[$key]) { 934 942 // don't allow params overwrite 935 943 $parsed[$key] = rawurldecode($value); … … 939 947 } 940 948 941 return array_merge($GLOBALS['_MDB2_dsninfo_default'], $parsed);949 return $parsed; 942 950 } 943 951 … … 1002 1010 $level = E_USER_NOTICE, $debuginfo = null, $dummy = null) 1003 1011 { 1004 if ( is_null($code)) {1012 if (null === $code) { 1005 1013 $code = MDB2_ERROR; 1006 1014 } … … 1147 1155 * <li>$options['datatype_map'] -> array: map user defined datatypes to other primitive datatypes</li> 1148 1156 * <li>$options['datatype_map_callback'] -> array: callback function/method that should be called</li> 1149 * <li>$options['bindname_format'] -> string: regular expression pattern for named parameters 1157 * <li>$options['bindname_format'] -> string: regular expression pattern for named parameters</li> 1158 * <li>$options['multi_query'] -> boolean: determines if queries returning multiple result sets should be executed</li> 1150 1159 * <li>$options['max_identifiers_length'] -> integer: max identifier length</li> 1160 * <li>$options['default_fk_action_onupdate'] -> string: default FOREIGN KEY ON UPDATE action ['RESTRICT'|'NO ACTION'|'SET DEFAULT'|'SET NULL'|'CASCADE']</li> 1161 * <li>$options['default_fk_action_ondelete'] -> string: default FOREIGN KEY ON DELETE action ['RESTRICT'|'NO ACTION'|'SET DEFAULT'|'SET NULL'|'CASCADE']</li> 1151 1162 * </ul> 1152 1163 * … … 1198 1209 'bindname_format' => '(?:\d+)|(?:[a-zA-Z][a-zA-Z0-9_]*)', 1199 1210 'max_identifiers_length' => 30, 1211 'default_fk_action_onupdate' => 'RESTRICT', 1212 'default_fk_action_ondelete' => 'RESTRICT', 1200 1213 ); 1201 1214 … … 1428 1441 * without the message string. 1429 1442 * 1430 * @param mixed integer error code, or a PEAR error object (all other 1431 * parameters are ignored if this parameter is an object 1432 * @param int error mode, see PEAR_Error docs 1433 * @param mixed If error mode is PEAR_ERROR_TRIGGER, this is the 1434 * error level (E_USER_NOTICE etc). If error mode is 1435 * PEAR_ERROR_CALLBACK, this is the callback function, 1436 * either as a function name, or as an array of an 1437 * object and method name. For other error modes this 1438 * parameter is ignored. 1439 * @param string Extra debug information. Defaults to the last 1440 * query and native error code. 1441 * @param string name of the method that triggered the error 1442 * 1443 * @return PEAR_Error instance of a PEAR Error object 1444 * 1445 * @access public 1446 * @see PEAR_Error 1447 */ 1448 function &raiseError($code = null, $mode = null, $options = null, $userinfo = null, $method = null) 1449 { 1443 * @param mixed $code integer error code, or a PEAR error object (all 1444 * other parameters are ignored if this parameter is 1445 * an object 1446 * @param int $mode error mode, see PEAR_Error docs 1447 * @param mixed $options If error mode is PEAR_ERROR_TRIGGER, this is the 1448 * error level (E_USER_NOTICE etc). If error mode is 1449 * PEAR_ERROR_CALLBACK, this is the callback function, 1450 * either as a function name, or as an array of an 1451 * object and method name. For other error modes this 1452 * parameter is ignored. 1453 * @param string $userinfo Extra debug information. Defaults to the last 1454 * query and native error code. 1455 * @param string $method name of the method that triggered the error 1456 * @param string $dummy1 not used 1457 * @param bool $dummy2 not used 1458 * 1459 * @return PEAR_Error instance of a PEAR Error object 1460 * @access public 1461 * @see PEAR_Error 1462 */ 1463 function &raiseError($code = null, 1464 $mode = null, 1465 $options = null, 1466 $userinfo = null, 1467 $method = null, 1468 $dummy1 = null, 1469 $dummy2 = false 1470 ) { 1450 1471 $userinfo = "[Error message: $userinfo]\n"; 1451 1472 // The error is yet a MDB2 error object … … 1453 1474 // because we use the static PEAR::raiseError, our global 1454 1475 // handler should be used if it is set 1455 if ( is_null($mode) && !empty($this->_default_error_mode)) {1476 if ((null === $mode) && !empty($this->_default_error_mode)) { 1456 1477 $mode = $this->_default_error_mode; 1457 1478 $options = $this->_default_error_options; 1458 1479 } 1459 if ( is_null($userinfo)) {1480 if (null === $userinfo) { 1460 1481 $userinfo = $code->getUserinfo(); 1461 1482 } … … 1470 1491 $native_errno = $native_msg = null; 1471 1492 list($code, $native_errno, $native_msg) = $this->errorInfo($code); 1472 if ( !is_null($native_errno) && $native_errno !== '') {1493 if ((null !== $native_errno) && $native_errno !== '') { 1473 1494 $userinfo.= "[Native code: $native_errno]\n"; 1474 1495 } 1475 if ( !is_null($native_msg) && $native_msg !== '') {1496 if ((null !== $native_msg) && $native_msg !== '') { 1476 1497 $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n"; 1477 1498 } 1478 if ( !is_null($method)) {1499 if (null !== $method) { 1479 1500 $userinfo = $method.': '.$userinfo; 1480 1501 } … … 1927 1948 } 1928 1949 $this->{$property} = new $class_name($this->db_index); 1929 $this->modules[$module] = $this->{$property};1950 $this->modules[$module] =& $this->{$property}; 1930 1951 if ($version) { 1931 1952 // this will be used in the connect method to determine if the module … … 1974 1995 } 1975 1996 } 1976 if ( !is_null($module)) {1997 if (null !== $module) { 1977 1998 return call_user_func_array(array(&$this->modules[$module], $method), $params); 1978 1999 } … … 2184 2205 function failNestedTransaction($error = null, $immediately = false) 2185 2206 { 2186 if ( is_null($error)) {2207 if (null !== $error) { 2187 2208 $error = $this->has_transaction_error ? $this->has_transaction_error : true; 2188 2209 } elseif (!$error) { … … 2266 2287 * Log out and disconnect from the database. 2267 2288 * 2268 * @param bool if the disconnect should be forced even if the 2269 * connection is opened persistently 2270 * 2271 * @return mixed true on success, false if not connected and error 2272 * object on error 2289 * @param boolean $force whether the disconnect should be forced even if the 2290 * connection is opened persistently 2291 * 2292 * @return mixed true on success, false if not connected and error object on error 2273 2293 * 2274 2294 * @access public … … 2386 2406 2387 2407 // }}} 2408 // {{{ _isNewLinkSet() 2409 2410 /** 2411 * Check if the 'new_link' option is set 2412 * 2413 * @return boolean 2414 * 2415 * @access protected 2416 */ 2417 function _isNewLinkSet() 2418 { 2419 return (isset($this->dsn['new_link']) 2420 && ($this->dsn['new_link'] === true 2421 || (is_string($this->dsn['new_link']) && preg_match('/^true$/i', $this->dsn['new_link'])) 2422 || (is_numeric($this->dsn['new_link']) && 0 != (int)$this->dsn['new_link']) 2423 ) 2424 ); 2425 } 2426 2427 // }}} 2388 2428 // {{{ function &standaloneQuery($query, $types = null, $is_manip = false) 2389 2429 … … 2564 2604 2565 2605 // }}} 2566 // {{{ function &_wrapResult($result , $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)2606 // {{{ function &_wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null) 2567 2607 2568 2608 /** … … 2635 2675 return $err; 2636 2676 } 2637 $result = new $result_wrap_class($result , $this->fetchmode);2677 $result = new $result_wrap_class($result_resource, $this->fetchmode); 2638 2678 } 2639 2679 return $result; … … 2683 2723 } 2684 2724 $this->limit = $limit; 2685 if ( !is_null($offset)) {2725 if (null !== $offset) { 2686 2726 $offset = (int)$offset; 2687 2727 if ($offset < 0) { … … 2740 2780 * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 2741 2781 * query, except that if there is already a row in the table with the same 2742 * key field values, the REPLACE query just updates its values instead of 2743 * inserting a new row. 2782 * key field values, the old row is deleted before the new row is inserted. 2744 2783 * 2745 2784 * The REPLACE type of query does not make part of the SQL standards. Since … … 2913 2952 } 2914 2953 $placeholder_type_guess = $placeholder_type = null; 2915 $question = '?';2916 $colon = ':';2954 $question = '?'; 2955 $colon = ':'; 2917 2956 $positions = array(); 2918 $position = 0; 2919 2957 $position = 0; 2920 2958 while ($position < strlen($query)) { 2921 2959 $q_position = strpos($query, $question, $position); … … 2930 2968 break; 2931 2969 } 2932 if ( is_null($placeholder_type)) {2970 if (null === $placeholder_type) { 2933 2971 $placeholder_type_guess = $query[$p_position]; 2934 2972 } … … 2944 2982 2945 2983 if ($query[$position] == $placeholder_type_guess) { 2946 if ( is_null($placeholder_type)) {2984 if (null === $placeholder_type) { 2947 2985 $placeholder_type = $query[$p_position]; 2948 2986 $question = $colon = $placeholder_type; … … 3008 3046 function _skipDelimitedStrings($query, $position, $p_position) 3009 3047 { 3010 $ignores[] = $this->string_quoting; 3011 $ignores[] = $this->identifier_quoting; 3012 3048 $ignores = $this->string_quoting; 3049 $ignores[] = $this->identifier_quoting; 3013 3050 $ignores = array_merge($ignores, $this->sql_comments); 3014 3051 … … 3028 3065 } 3029 3066 } while ($ignore['escape'] 3030 && $end_quote-1 != $start_quote 3031 && $query[($end_quote - 1)] == $ignore['escape'] 3032 && ($ignore['escape_pattern'] !== $ignore['escape'] 3033 || $query[($end_quote - 2)] != $ignore['escape'])); 3067 && $end_quote-1 != $start_quote 3068 && $query[($end_quote - 1)] == $ignore['escape'] 3069 && ( $ignore['escape_pattern'] !== $ignore['escape'] 3070 || $query[($end_quote - 2)] != $ignore['escape']) 3071 ); 3072 3034 3073 $position = $end_quote + 1; 3035 3074 return $position; … … 3171 3210 { 3172 3211 return sprintf($this->options['idxname_format'], 3173 preg_replace('/[^a-z0-9_\ $]/i', '_', $idx));3212 preg_replace('/[^a-z0-9_\-\$.]/i', '_', $idx)); 3174 3213 } 3175 3214 … … 3240 3279 * the result set. 3241 3280 * 3242 * @param stringthe SELECT query statement to be executed.3243 * @param stringoptional argument that specifies the expected3244 * datatype of the result set field, so that an eventual conversion3245 * may be performed. The default datatype is text, meaning that no3246 * conversion is performed3247 * @param int the column numberto fetch3281 * @param string $query the SELECT query statement to be executed. 3282 * @param string $type optional argument that specifies the expected 3283 * datatype of the result set field, so that an eventual 3284 * conversion may be performed. The default datatype is 3285 * text, meaning that no conversion is performed 3286 * @param mixed $colnum the column number (or name) to fetch 3248 3287 * 3249 3288 * @return mixed MDB2_OK or field value on success, a MDB2 error on failure … … 3301 3340 * each row of the result set into an array and then frees the result set. 3302 3341 * 3303 * @param stringthe SELECT query statement to be executed.3304 * @param stringoptional argument that specifies the expected3305 * datatype of the result set field, so that an eventual conversion3306 * may be performed. The default datatype is text, meaning that no3307 * conversion is performed3308 * @param int the row numberto fetch3342 * @param string $query the SELECT query statement to be executed. 3343 * @param string $type optional argument that specifies the expected 3344 * datatype of the result set field, so that an eventual 3345 * conversion may be performed. The default datatype is text, 3346 * meaning that no conversion is performed 3347 * @param mixed $colnum the column number (or name) to fetch 3309 3348 * 3310 3349 * @return mixed MDB2_OK or data array on success, a MDB2 error on failure 3311 *3312 3350 * @access public 3313 3351 */ … … 3519 3557 * fetch single column from the next row from a result set 3520 3558 * 3521 * @param int the column number to fetch 3522 * @param int number of the row where the data can be found 3523 * 3524 * @return string data on success, a MDB2 error on failure 3525 * 3559 * @param int|string the column number (or name) to fetch 3560 * @param int number of the row where the data can be found 3561 * 3562 * @return string data on success, a MDB2 error on failure 3526 3563 * @access public 3527 3564 */ … … 3546 3583 * Fetch and return a column from the current row pointer position 3547 3584 * 3548 * @param int the column number to fetch 3549 * 3550 * @return mixed data array on success, a MDB2 error on failure 3551 * 3585 * @param int|string the column number (or name) to fetch 3586 * 3587 * @return mixed data array on success, a MDB2 error on failure 3552 3588 * @access public 3553 3589 */ … … 3610 3646 3611 3647 $shift_array = $rekey ? false : null; 3612 if ( !is_null($shift_array)) {3648 if (null !== $shift_array) { 3613 3649 if (is_object($row)) { 3614 3650 $colnum = count(get_object_vars($row)); … … 3816 3852 } 3817 3853 $this->values[$column] =& $value; 3818 if ( !is_null($type)) {3854 if (null !== $type) { 3819 3855 $this->types[$column] = $type; 3820 3856 } … … 3986 4022 } 3987 4023 $this->values[$parameter] = $value; 3988 if ( !is_null($type)) {4024 if (null !== $type) { 3989 4025 $this->types[$parameter] = $type; 3990 4026 } … … 4055 4091 } 4056 4092 $this->values[$parameter] =& $value; 4057 if ( !is_null($type)) {4093 if (null !== $type) { 4058 4094 $this->types[$parameter] = $type; 4059 4095 } … … 4096 4132 * Execute a prepared query statement. 4097 4133 * 4098 * @param arrayspecifies all necessary information4099 * for bindParam() the array elements must use keys corresponding to4100 * the number of the position of the parameter.4101 * @param mixedspecifies which result class to use4102 * @param mixedspecifies which class to wrap results in4103 * 4104 * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure4105 * 4106 * @access public4134 * @param array specifies all necessary information 4135 * for bindParam() the array elements must use keys corresponding 4136 * to the number of the position of the parameter. 4137 * @param mixed specifies which result class to use 4138 * @param mixed specifies which class to wrap results in 4139 * 4140 * @return mixed MDB2_Result or integer (affected rows) on success, 4141 * a MDB2 error on failure 4142 * @access public 4107 4143 */ 4108 4144 function &execute($values = null, $result_class = true, $result_wrap_class = false) 4109 4145 { 4110 if ( is_null($this->positions)) {4146 if (null === $this->positions) { 4111 4147 return $this->db->raiseError(MDB2_ERROR, null, null, 4112 4148 'Prepared statement has already been freed', __FUNCTION__); … … 4134 4170 * @param mixed specifies which class to wrap results in 4135 4171 * 4136 * @return mixed MDB2_Result or integer on success, a MDB2 error on failure4137 * 4172 * @return mixed MDB2_Result or integer (affected rows) on success, 4173 * a MDB2 error on failure 4138 4174 * @access private 4139 4175 */ … … 4186 4222 function free() 4187 4223 { 4188 if ( is_null($this->positions)) {4224 if (null === $this->positions) { 4189 4225 return $this->db->raiseError(MDB2_ERROR, null, null, 4190 4226 'Prepared statement has already been freed', __FUNCTION__); -
trunk/roundcubemail/program/lib/MDB2/Date.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Date.php ,v 1.10 2006/03/01 12:15:32 lsmith Exp$45 // $Id: Date.php 208329 2006-03-01 12:15:38Z lsmith $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/Common.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Common.php ,v 1.137 2008/02/17 18:53:40 afz Exp$45 // $Id: Common.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 47 47 require_once 'MDB2/LOB.php'; … … 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 } … … 314 314 reset($types); 315 315 foreach (array_keys($sorted_types) as $k) { 316 if ( is_null($sorted_types[$k])) {316 if (null === $sorted_types[$k]) { 317 317 $sorted_types[$k] = current($types); 318 318 next($types); … … 512 512 } 513 513 } 514 if ( !is_null($field['default'])) {514 if (null !== $field['default']) { 515 515 $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']); 516 516 } … … 1120 1120 } 1121 1121 1122 if ( is_null($value)1122 if ((null === $value) 1123 1123 || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) 1124 1124 ) { … … 1129 1129 } 1130 1130 1131 if ( is_null($type)) {1131 if (null === $type) { 1132 1132 switch (gettype($value)) { 1133 1133 case 'integer': … … 1289 1289 function _quoteLOB($value, $quote, $escape_wildcards) 1290 1290 { 1291 $value = $this->_readFile($value); 1292 if (PEAR::isError($value)) { 1293 return $value; 1291 $db =& $this->getDBInstance(); 1292 if (PEAR::isError($db)) { 1293 return $db; 1294 } 1295 if ($db->options['lob_allow_url_include']) { 1296 $value = $this->_readFile($value); 1297 if (PEAR::isError($value)) { 1298 return $value; 1299 } 1294 1300 } 1295 1301 return $this->_quoteText($value, $quote, $escape_wildcards); … … 1555 1561 function _retrieveLOB(&$lob) 1556 1562 { 1557 if ( is_null($lob['value'])) {1563 if (null === $lob['value']) { 1558 1564 $lob['value'] = $lob['resource']; 1559 1565 } … … 1688 1694 1689 1695 $match = ''; 1690 if ( !is_null($operator)) {1696 if (null !== $operator) { 1691 1697 $operator = strtoupper($operator); 1692 1698 switch ($operator) { 1693 1699 // case insensitive 1694 1700 case 'ILIKE': 1695 if ( is_null($field)) {1701 if (null === $field) { 1696 1702 return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 1697 1703 'case insensitive LIKE matching requires passing the field name', __FUNCTION__); … … 1700 1706 $match = $db->function->lower($field).' LIKE '; 1701 1707 break; 1708 case 'NOT ILIKE': 1709 if (null === $field) { 1710 return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 1711 'case insensitive NOT ILIKE matching requires passing the field name', __FUNCTION__); 1712 } 1713 $db->loadModule('Function', null, true); 1714 $match = $db->function->lower($field).' NOT LIKE '; 1715 break; 1702 1716 // case sensitive 1703 1717 case 'LIKE': 1704 $match = is_null($field) ? 'LIKE ' : $field.' LIKE '; 1718 $match = (null === $field) ? 'LIKE ' : ($field.' LIKE '); 1719 break; 1720 case 'NOT LIKE': 1721 $match = (null === $field) ? 'NOT LIKE ' : ($field.' NOT LIKE '); 1705 1722 break; 1706 1723 default: … … 1714 1731 $match.= $value; 1715 1732 } else { 1716 if ($operator === 'ILIKE') {1717 $value = strtolower($value);1718 }1719 1733 $escaped = $db->escape($value); 1720 1734 if (PEAR::isError($escaped)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/mssql.php
r1352 r3227 45 45 // +----------------------------------------------------------------------+ 46 46 // 47 // $Id: mssql.php ,v 1.65 2008/02/19 14:54:17 afz Exp$47 // $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $ 48 48 // 49 49 … … 72 72 function _baseConvertResult($value, $type, $rtrim = true) 73 73 { 74 if ( is_null($value)) {74 if (null === $value) { 75 75 return null; 76 76 } … … 229 229 $field['default'] = 0; 230 230 } 231 if ( is_null($field['default'])) {231 if (null === $field['default']) { 232 232 $default = ' DEFAULT (null)'; 233 233 } else { … … 337 337 $value = '0x'.bin2hex($this->_readFile($value)); 338 338 return $value; 339 } 340 341 // }}} 342 // {{{ matchPattern() 343 344 /** 345 * build a pattern matching string 346 * 347 * @access public 348 * 349 * @param array $pattern even keys are strings, odd are patterns (% and _) 350 * @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future) 351 * @param string $field optional field name that is being matched against 352 * (might be required when emulating ILIKE) 353 * 354 * @return string SQL pattern 355 */ 356 function matchPattern($pattern, $operator = null, $field = null) 357 { 358 $db =& $this->getDBInstance(); 359 if (PEAR::isError($db)) { 360 return $db; 361 } 362 363 $match = ''; 364 if (null !== $operator) { 365 $field = (null === $field) ? '' : $field.' '; 366 $operator = strtoupper($operator); 367 switch ($operator) { 368 // case insensitive 369 case 'ILIKE': 370 $match = $field.'LIKE '; 371 break; 372 case 'NOT ILIKE': 373 $match = $field.'NOT LIKE '; 374 break; 375 // case sensitive 376 case 'LIKE': 377 $match = $field.'LIKE '; 378 break; 379 case 'NOT LIKE': 380 $match = $field.'NOT LIKE '; 381 break; 382 default: 383 return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 384 'not a supported operator type:'. $operator, __FUNCTION__); 385 } 386 } 387 $match.= "'"; 388 foreach ($pattern as $key => $value) { 389 if ($key % 2) { 390 $match.= $value; 391 } else { 392 $match.= $db->escapePattern($db->escape($value)); 393 } 394 } 395 $match.= "'"; 396 $match.= $this->patternEscapeString(); 397 return $match; 339 398 } 340 399 … … 377 436 $length = 8; 378 437 break; 438 case 'smalldatetime': 379 439 case 'datetime': 380 440 $type[0] = 'timestamp'; -
trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/mysql.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mysql.php ,v 1.65 2008/02/22 19:23:49 quipo Exp$46 // $Id: mysql.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 353 353 354 354 $match = ''; 355 if ( !is_null($operator)) {356 $field = is_null($field) ? '' : $field.' ';355 if (null !== $operator) { 356 $field = (null === $field) ? '' : $field.' '; 357 357 $operator = strtoupper($operator); 358 358 switch ($operator) { … … 361 361 $match = $field.'LIKE '; 362 362 break; 363 case 'NOT ILIKE': 364 $match = $field.'NOT LIKE '; 365 break; 363 366 // case sensitive 364 367 case 'LIKE': 365 368 $match = $field.'LIKE BINARY '; 369 break; 370 case 'NOT LIKE': 371 $match = $field.'NOT LIKE BINARY '; 366 372 break; 367 373 default: -
trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/mysqli.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mysqli.php ,v 1.63 2008/02/22 19:23:49 quipo Exp$46 // $Id: mysqli.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 353 353 354 354 $match = ''; 355 if ( !is_null($operator)) {356 $field = is_null($field) ? '' : $field.' ';355 if (null !== $operator) { 356 $field = (null === $field) ? '' : $field.' '; 357 357 $operator = strtoupper($operator); 358 358 switch ($operator) { … … 361 361 $match = $field.'LIKE '; 362 362 break; 363 case 'NOT ILIKE': 364 $match = $field.'NOT LIKE '; 365 break; 363 366 // case sensitive 364 367 case 'LIKE': 365 368 $match = $field.'LIKE BINARY '; 369 break; 370 case 'NOT LIKE': 371 $match = $field.'NOT LIKE BINARY '; 366 372 break; 367 373 default: -
trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/pgsql.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: pgsql.php ,v 1.91 2008/03/09 12:28:08 quipo Exp$45 // $Id: pgsql.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 47 47 require_once 'MDB2/Driver/Datatype/Common.php'; … … 69 69 function _baseConvertResult($value, $type, $rtrim = true) 70 70 { 71 if ( is_null($value)) {71 if (null === $value) { 72 72 return null; 73 73 } … … 125 125 switch ($field['type']) { 126 126 case 'text': 127 $length = !empty($field['length']) 128 ? $field['length'] : $db->options['default_text_field_length']; 127 $length = !empty($field['length']) ? $field['length'] : false; 129 128 $fixed = !empty($field['fixed']) ? $field['fixed'] : false; 130 129 return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') … … 241 240 function _quoteCLOB($value, $quote, $escape_wildcards) 242 241 { 242 $db =& $this->getDBInstance(); 243 if (PEAR::isError($db)) { 244 return $db; 245 } 246 if ($db->options['lob_allow_url_include']) { 247 $value = $this->_readFile($value); 248 if (PEAR::isError($value)) { 249 return $value; 250 } 251 } 243 252 return $this->_quoteText($value, $quote, $escape_wildcards); 244 253 } … … 263 272 return $value; 264 273 } 274 $db =& $this->getDBInstance(); 275 if (PEAR::isError($db)) { 276 return $db; 277 } 278 if ($db->options['lob_allow_url_include']) { 279 $value = $this->_readFile($value); 280 if (PEAR::isError($value)) { 281 return $value; 282 } 283 } 265 284 if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) { 266 $db =& $this->getDBInstance();267 if (PEAR::isError($db)) {268 return $db;269 }270 285 $connection = $db->getConnection(); 271 286 if (PEAR::isError($connection)) { … … 325 340 326 341 $match = ''; 327 if ( !is_null($operator)) {328 $field = is_null($field) ? '' : $field.' ';342 if (null !== $operator) { 343 $field = (null === $field) ? '' : $field.' '; 329 344 $operator = strtoupper($operator); 330 345 switch ($operator) { … … 333 348 $match = $field.'ILIKE '; 334 349 break; 350 case 'NOT ILIKE': 351 $match = $field.'NOT ILIKE '; 352 break; 335 353 // case sensitive 336 354 case 'LIKE': 337 355 $match = $field.'LIKE '; 356 break; 357 case 'NOT LIKE': 358 $match = $field.'NOT LIKE '; 338 359 break; 339 360 default: -
trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/sqlite.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: sqlite.php ,v 1.67 2008/02/22 19:58:06 quipo Exp$46 // $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 244 244 245 245 $match = ''; 246 if ( !is_null($operator)) {247 $field = is_null($field) ? '' : $field.' ';246 if (null !== $operator) { 247 $field = (null === $field) ? '' : $field.' '; 248 248 $operator = strtoupper($operator); 249 249 switch ($operator) { … … 252 252 $match = $field.'LIKE '; 253 253 break; 254 case 'NOT ILIKE': 255 $match = $field.'NOT LIKE '; 256 break; 254 257 // case sensitive 255 258 case 'LIKE': 256 259 $match = $field.'LIKE '; 260 break; 261 case 'NOT LIKE': 262 $match = $field.'NOT LIKE '; 257 263 break; 258 264 default: -
trunk/roundcubemail/program/lib/MDB2/Driver/Function/Common.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Common.php ,v 1.21 2008/02/17 18:51:39 quipo Exp$45 // $Id: Common.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 167 167 function substring($value, $position = 1, $length = null) 168 168 { 169 if ( !is_null($length)) {169 if (null !== $length) { 170 170 return "SUBSTRING($value FROM $position FOR $length)"; 171 171 } -
trunk/roundcubemail/program/lib/MDB2/Driver/Function/mssql.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mssql.php ,v 1.16 2008/02/17 18:54:08 quipo Exp$45 // $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 135 135 function substring($value, $position = 1, $length = null) 136 136 { 137 if ( !is_null($length)) {137 if (null !== $length) { 138 138 return "SUBSTRING($value, $position, $length)"; 139 139 } -
trunk/roundcubemail/program/lib/MDB2/Driver/Function/mysql.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysql.php ,v 1.12 2008/02/17 18:54:08 quipo Exp$45 // $Id: mysql.php 253106 2008-02-17 18:54:08Z quipo $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Function/mysqli.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysqli.php ,v 1.14 2008/02/17 18:54:08 quipo Exp$45 // $Id: mysqli.php 253106 2008-02-17 18:54:08Z quipo $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Function/pgsql.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: pgsql.php ,v 1.10 2008/02/17 18:54:08 quipo Exp$45 // $Id: pgsql.php 268669 2008-11-09 19:46:50Z quipo $ 46 46 47 47 require_once 'MDB2/Driver/Function/Common.php'; … … 94 94 function unixtimestamp($expression) 95 95 { 96 return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', TIMESTAMP '. $expression.'))';96 return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', CAST ((' . $expression . ') AS TIMESTAMP)))'; 97 97 } 98 98 -
trunk/roundcubemail/program/lib/MDB2/Driver/Function/sqlite.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: sqlite.php ,v 1.10 2008/02/17 18:54:08 quipo Exp$45 // $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 117 117 function substring($value, $position = 1, $length = null) 118 118 { 119 if ( !is_null($length)) {120 return "substr($value, $position,$length)";119 if (null !== $length) { 120 return "substr($value, $position, $length)"; 121 121 } 122 return "substr($value, $position,length($value))";122 return "substr($value, $position, length($value))"; 123 123 } 124 124 -
trunk/roundcubemail/program/lib/MDB2/Driver/Manager/Common.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: Common.php ,v 1.71 2008/02/12 23:12:27 quipo Exp$46 // $Id: Common.php 273526 2009-01-14 15:01:21Z quipo $ 47 47 // 48 48 … … 70 70 /** 71 71 * Split the "[owner|schema].table" notation into an array 72 * 73 * @param string $table [schema and] table name 74 * 75 * @return array array(schema, table) 72 76 * @access private 73 77 */ -
trunk/roundcubemail/program/lib/MDB2/Driver/Manager/mssql.php
r1352 r3227 45 45 // +----------------------------------------------------------------------+ 46 46 // 47 // $Id: mssql.php ,v 1.109 2008/03/05 12:55:57 afz Exp$47 // $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $ 48 48 // 49 49 … … 716 716 } 717 717 718 $table = $db->quote Identifier($table, true);718 $table = $db->quote($table, 'text'); 719 719 $columns = $db->queryCol("SELECT c.name 720 720 FROM syscolumns c 721 721 LEFT JOIN sysobjects o ON c.id = o.id 722 WHERE o.name = '$table'");722 WHERE o.name = $table"); 723 723 if (PEAR::isError($columns)) { 724 724 return $columns; … … 894 894 WHERE xtype = 'TR' 895 895 AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0"; 896 if ( !is_null($table)) {896 if (null !== $table) { 897 897 $query .= " AND object_name(parent_obj) = $table"; 898 898 } … … 995 995 return $db; 996 996 } 997 $table = $db->quote Identifier($table, true);997 $table = $db->quote($table, 'text'); 998 998 999 999 $query = "SELECT c.constraint_name 1000 1000 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS c 1001 1001 WHERE c.constraint_catalog = DB_NAME() 1002 AND c.table_name = '$table'";1002 AND c.table_name = $table"; 1003 1003 $constraints = $db->queryCol($query); 1004 1004 if (PEAR::isError($constraints)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/Manager/mysql.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysql.php ,v 1.108 2008/03/11 19:58:12 quipo Exp$45 // $Id: mysql.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 223 223 } 224 224 } 225 if ( !is_null($autoincrement) && count($pk_fields) > 1) {225 if ((null !== $autoincrement) && count($pk_fields) > 1) { 226 226 $options['primary'] = $pk_fields; 227 227 } else { … … 236 236 } 237 237 238 if ( !is_null($autoincrement)) {238 if (null !== $autoincrement) { 239 239 // we have to remove the PK clause added by _getIntegerDeclaration() 240 240 $query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query); … … 660 660 661 661 $query = 'SHOW TRIGGERS'; 662 if ( !is_null($table)) {662 if (null !== $table) { 663 663 $table = $db->quote($table, 'text'); 664 664 $query .= " LIKE $table"; … … 692 692 693 693 $query = "SHOW /*!50002 FULL*/ TABLES"; 694 if ( !is_null($database)) {694 if (null !== $database) { 695 695 $query .= " FROM $database"; 696 696 } … … 732 732 733 733 $query = 'SHOW FULL TABLES'; 734 if ( !is_null($database)) {734 if (null !== $database) { 735 735 $query.= " FROM $database"; 736 736 } … … 941 941 942 942 $type = ''; 943 $ name = $db->quoteIdentifier($db->getIndexName($name), true);943 $idx_name = $db->quoteIdentifier($db->getIndexName($name), true); 944 944 if (!empty($definition['primary'])) { 945 945 $type = 'PRIMARY'; 946 $ name = 'KEY';946 $idx_name = 'KEY'; 947 947 } elseif (!empty($definition['unique'])) { 948 948 $type = 'UNIQUE'; … … 956 956 957 957 $table_quoted = $db->quoteIdentifier($table, true); 958 $query = "ALTER TABLE $table_quoted ADD $type $ name";958 $query = "ALTER TABLE $table_quoted ADD $type $idx_name"; 959 959 if (!empty($definition['foreign'])) { 960 960 $query .= ' FOREIGN KEY'; 961 961 } 962 962 $fields = array(); 963 foreach (array_keys($definition['fields']) as $field) { 964 $fields[] = $db->quoteIdentifier($field, true); 963 foreach ($definition['fields'] as $field => $fieldinfo) { 964 $quoted = $db->quoteIdentifier($field, true); 965 if (!empty($fieldinfo['length'])) { 966 $quoted .= '(' . $fieldinfo['length'] . ')'; 967 } 968 $fields[] = $quoted; 965 969 } 966 970 $query .= ' ('. implode(', ', $fields) . ')'; … … 973 977 $query .= ' ('. implode(', ', $referenced_fields) . ')'; 974 978 $query .= $this->_getAdvancedFKOptions($definition); 979 980 // add index on FK column(s) or we can't add a FK constraint 981 // @see http://forums.mysql.com/read.php?22,19755,226009 982 $result = $this->createIndex($table, $name.'_fkidx', $definition); 983 if (PEAR::isError($result)) { 984 return $result; 985 } 975 986 } 976 987 $res = $db->exec($query); … … 1054 1065 // create triggers to enforce FOREIGN KEY constraints 1055 1066 if ($db->supports('triggers') && !empty($foreign_keys)) { 1056 $table = $db->quoteIdentifier($table, true);1067 $table_quoted = $db->quoteIdentifier($table, true); 1057 1068 foreach ($foreign_keys as $fkname => $fkdef) { 1058 1069 if (empty($fkdef)) { 1059 1070 continue; 1060 1071 } 1061 //set actions to 'RESTRICT'if not set1062 $fkdef['onupdate'] = empty($fkdef['onupdate']) ? 'RESTRICT': strtoupper($fkdef['onupdate']);1063 $fkdef['ondelete'] = empty($fkdef['ondelete']) ? 'RESTRICT': strtoupper($fkdef['ondelete']);1072 //set actions to default if not set 1073 $fkdef['onupdate'] = empty($fkdef['onupdate']) ? $db->options['default_fk_action_onupdate'] : strtoupper($fkdef['onupdate']); 1074 $fkdef['ondelete'] = empty($fkdef['ondelete']) ? $db->options['default_fk_action_ondelete'] : strtoupper($fkdef['ondelete']); 1064 1075 1065 1076 $trigger_names = array( … … 1076 1087 $aliased_fields = array(); 1077 1088 foreach ($table_fields as $field) { 1078 $aliased_fields[] = $table .'.'.$field .' AS '.$field;1089 $aliased_fields[] = $table_quoted .'.'.$field .' AS '.$field; 1079 1090 } 1080 1091 $restrict_action .= implode(',', $aliased_fields) 1081 .' FROM '.$table 1092 .' FROM '.$table_quoted 1082 1093 .' WHERE '; 1083 1094 $conditions = array(); … … 1089 1100 $null_values[] = $table_fields[$i] .' = NULL'; 1090 1101 } 1091 $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL' 1092 .' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();' 1093 .' END IF;'; 1094 1095 $cascade_action_update = 'UPDATE '.$table.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';'; 1096 $cascade_action_delete = 'DELETE FROM '.$table.' WHERE '.implode(' AND ', $conditions). ';'; 1097 $setnull_action = 'UPDATE '.$table.' SET '.implode(', ', $null_values).' WHERE '.implode(' AND ', $conditions). ';'; 1102 $conditions2 = array(); 1103 if ('NO ACTION' != $fkdef['ondelete']) { 1104 // There is no NEW row in on DELETE trigger 1105 for ($i=0; $i<count($referenced_fields); $i++) { 1106 $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <> OLD.'.$referenced_fields[$i]; 1107 } 1108 } 1109 1110 $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL'; 1111 if (!empty($conditions2)) { 1112 $restrict_action .= ' AND (' .implode(' OR ', $conditions2) .')'; 1113 } 1114 $restrict_action .= ' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();' 1115 .' END IF;'; 1116 1117 $cascade_action_update = 'UPDATE '.$table_quoted.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';'; 1118 $cascade_action_delete = 'DELETE FROM '.$table_quoted.' WHERE '.implode(' AND ', $conditions). ';'; 1119 $setnull_action = 'UPDATE '.$table_quoted.' SET '.implode(', ', $null_values).' WHERE '.implode(' AND ', $conditions). ';'; 1098 1120 1099 1121 if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) { … … 1107 1129 $default_values[] = $table_field .' = '. $field_definition[0]['default']; 1108 1130 } 1109 $setdefault_action = 'UPDATE '.$table .' SET '.implode(', ', $default_values).' WHERE '.implode(' AND ', $conditions). ';';1131 $setdefault_action = 'UPDATE '.$table_quoted.' SET '.implode(', ', $default_values).' WHERE '.implode(' AND ', $conditions). ';'; 1110 1132 } 1111 1133 … … 1123 1145 } elseif ('NO ACTION' == $fkdef['onupdate']) { 1124 1146 $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update'); 1125 } else { 1126 //'RESTRICT' 1147 } elseif ('RESTRICT' == $fkdef['onupdate']) { 1127 1148 $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update'); 1128 1149 } … … 1135 1156 } elseif ('NO ACTION' == $fkdef['ondelete']) { 1136 1157 $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete'); 1137 } else { 1138 //'RESTRICT' 1158 } elseif ('RESTRICT' == $fkdef['ondelete']) { 1139 1159 $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete'); 1140 1160 } … … 1394 1414 1395 1415 $query = "SHOW TABLES"; 1396 if ( !is_null($database)) {1416 if (null !== $database) { 1397 1417 $query .= " FROM $database"; 1398 1418 } -
trunk/roundcubemail/program/lib/MDB2/Driver/Manager/mysqli.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysqli.php ,v 1.95 2008/03/11 19:58:12 quipo Exp$45 // $Id: mysqli.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 223 223 } 224 224 } 225 if ( !is_null($autoincrement) && count($pk_fields) > 1) {225 if ((null !== $autoincrement) && count($pk_fields) > 1) { 226 226 $options['primary'] = $pk_fields; 227 227 } else { … … 236 236 } 237 237 238 if ( !is_null($autoincrement)) {238 if (null !== $autoincrement) { 239 239 // we have to remove the PK clause added by _getIntegerDeclaration() 240 240 $query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query); … … 660 660 661 661 $query = 'SHOW TRIGGERS'; 662 if ( !is_null($table)) {662 if (null !== $table) { 663 663 $table = $db->quote($table, 'text'); 664 664 $query .= " LIKE $table"; … … 692 692 693 693 $query = "SHOW /*!50002 FULL*/ TABLES"; 694 if ( !is_null($database)) {694 if (null !== $database) { 695 695 $query .= " FROM $database"; 696 696 } … … 732 732 733 733 $query = 'SHOW FULL TABLES'; 734 if ( !is_null($database)) {734 if (null !== $database) { 735 735 $query.= " FROM $database"; 736 736 } … … 941 941 942 942 $type = ''; 943 $ name = $db->quoteIdentifier($db->getIndexName($name), true);943 $idx_name = $db->quoteIdentifier($db->getIndexName($name), true); 944 944 if (!empty($definition['primary'])) { 945 945 $type = 'PRIMARY'; 946 $ name = 'KEY';946 $idx_name = 'KEY'; 947 947 } elseif (!empty($definition['unique'])) { 948 948 $type = 'UNIQUE'; … … 956 956 957 957 $table_quoted = $db->quoteIdentifier($table, true); 958 $query = "ALTER TABLE $table_quoted ADD $type $ name";958 $query = "ALTER TABLE $table_quoted ADD $type $idx_name"; 959 959 if (!empty($definition['foreign'])) { 960 960 $query .= ' FOREIGN KEY'; 961 961 } 962 962 $fields = array(); 963 foreach (array_keys($definition['fields']) as $field) { 964 $fields[] = $db->quoteIdentifier($field, true); 963 foreach ($definition['fields'] as $field => $fieldinfo) { 964 $quoted = $db->quoteIdentifier($field, true); 965 if (!empty($fieldinfo['length'])) { 966 $quoted .= '(' . $fieldinfo['length'] . ')'; 967 } 968 $fields[] = $quoted; 965 969 } 966 970 $query .= ' ('. implode(', ', $fields) . ')'; … … 973 977 $query .= ' ('. implode(', ', $referenced_fields) . ')'; 974 978 $query .= $this->_getAdvancedFKOptions($definition); 979 980 // add index on FK column(s) or we can't add a FK constraint 981 // @see http://forums.mysql.com/read.php?22,19755,226009 982 $result = $this->createIndex($table, $name.'_fkidx', $definition); 983 if (PEAR::isError($result)) { 984 return $result; 985 } 975 986 } 976 987 $res = $db->exec($query); … … 1054 1065 // create triggers to enforce FOREIGN KEY constraints 1055 1066 if ($db->supports('triggers') && !empty($foreign_keys)) { 1056 $table = $db->quoteIdentifier($table, true);1067 $table_quoted = $db->quoteIdentifier($table, true); 1057 1068 foreach ($foreign_keys as $fkname => $fkdef) { 1058 1069 if (empty($fkdef)) { 1059 1070 continue; 1060 1071 } 1061 //set actions to 'RESTRICT'if not set1062 $fkdef['onupdate'] = empty($fkdef['onupdate']) ? 'RESTRICT': strtoupper($fkdef['onupdate']);1063 $fkdef['ondelete'] = empty($fkdef['ondelete']) ? 'RESTRICT': strtoupper($fkdef['ondelete']);1072 //set actions to default if not set 1073 $fkdef['onupdate'] = empty($fkdef['onupdate']) ? $db->options['default_fk_action_onupdate'] : strtoupper($fkdef['onupdate']); 1074 $fkdef['ondelete'] = empty($fkdef['ondelete']) ? $db->options['default_fk_action_ondelete'] : strtoupper($fkdef['ondelete']); 1064 1075 1065 1076 $trigger_names = array( … … 1076 1087 $aliased_fields = array(); 1077 1088 foreach ($table_fields as $field) { 1078 $aliased_fields[] = $table .'.'.$field .' AS '.$field;1089 $aliased_fields[] = $table_quoted .'.'.$field .' AS '.$field; 1079 1090 } 1080 1091 $restrict_action .= implode(',', $aliased_fields) 1081 .' FROM '.$table 1092 .' FROM '.$table_quoted 1082 1093 .' WHERE '; 1083 1094 $conditions = array(); … … 1089 1100 $null_values[] = $table_fields[$i] .' = NULL'; 1090 1101 } 1091 $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL' 1092 .' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();' 1093 .' END IF;'; 1094 1095 $cascade_action_update = 'UPDATE '.$table.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';'; 1096 $cascade_action_delete = 'DELETE FROM '.$table.' WHERE '.implode(' AND ', $conditions). ';'; 1097 $setnull_action = 'UPDATE '.$table.' SET '.implode(', ', $null_values).' WHERE '.implode(' AND ', $conditions). ';'; 1102 $conditions2 = array(); 1103 if ('NO ACTION' != $fkdef['ondelete']) { 1104 // There is no NEW row in on DELETE trigger 1105 for ($i=0; $i<count($referenced_fields); $i++) { 1106 $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <> OLD.'.$referenced_fields[$i]; 1107 } 1108 } 1109 1110 $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL'; 1111 if (!empty($conditions2)) { 1112 $restrict_action .= ' AND (' .implode(' OR ', $conditions2) .')'; 1113 } 1114 $restrict_action .= ' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();' 1115 .' END IF;'; 1116 1117 $cascade_action_update = 'UPDATE '.$table_quoted.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';'; 1118 $cascade_action_delete = 'DELETE FROM '.$table_quoted.' WHERE '.implode(' AND ', $conditions). ';'; 1119 $setnull_action = 'UPDATE '.$table_quoted.' SET '.implode(', ', $null_values).' WHERE '.implode(' AND ', $conditions). ';'; 1098 1120 1099 1121 if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) { … … 1107 1129 $default_values[] = $table_field .' = '. $field_definition[0]['default']; 1108 1130 } 1109 $setdefault_action = 'UPDATE '.$table .' SET '.implode(', ', $default_values).' WHERE '.implode(' AND ', $conditions). ';';1131 $setdefault_action = 'UPDATE '.$table_quoted.' SET '.implode(', ', $default_values).' WHERE '.implode(' AND ', $conditions). ';'; 1110 1132 } 1111 1133 … … 1123 1145 } elseif ('NO ACTION' == $fkdef['onupdate']) { 1124 1146 $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update'); 1125 } else { 1126 //'RESTRICT' 1147 } elseif ('RESTRICT' == $fkdef['onupdate']) { 1127 1148 $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update'); 1128 1149 } … … 1135 1156 } elseif ('NO ACTION' == $fkdef['ondelete']) { 1136 1157 $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete'); 1137 } else { 1138 //'RESTRICT' 1158 } elseif ('RESTRICT' == $fkdef['ondelete']) { 1139 1159 $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete'); 1140 1160 } … … 1394 1414 1395 1415 $query = "SHOW TABLES"; 1396 if ( !is_null($database)) {1416 if (null !== $database) { 1397 1417 $query .= " FROM $database"; 1398 1418 } -
trunk/roundcubemail/program/lib/MDB2/Driver/Manager/pgsql.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: pgsql.php ,v 1.82 2008/03/05 12:55:57 afz Exp$45 // $Id: pgsql.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 47 47 require_once 'MDB2/Driver/Manager/Common.php'; … … 350 350 } 351 351 352 $name = $db->quoteIdentifier($name, true); 353 352 354 if (!empty($changes['remove']) && is_array($changes['remove'])) { 353 355 foreach ($changes['remove'] as $field_name => $field) { … … 394 396 } 395 397 $db->loadModule('Datatype', null, true); 396 $query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']); 398 $type = $db->datatype->getTypeDeclaration($field['definition']); 399 $query = "ALTER $field_name TYPE $type USING CAST($field_name AS $type)"; 397 400 $result = $db->exec("ALTER TABLE $name $query"); 398 401 if (PEAR::isError($result)) { … … 407 410 } 408 411 } 409 if ( !empty($field['definition']['notnull'])) {412 if (array_key_exists('notnull', $field['definition'])) { 410 413 $query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL'; 411 414 $result = $db->exec("ALTER TABLE $name $query"); … … 417 420 } 418 421 419 $name = $db->quoteIdentifier($name, true);420 422 if (!empty($changes['name'])) { 421 423 $change_name = $db->quoteIdentifier($changes['name'], true); … … 607 609 pg_class tbl 608 610 WHERE trg.tgrelid = tbl.oid'; 609 if ( !is_null($table)) {611 if (null !== $table) { 610 612 $table = $db->quote(strtoupper($table), 'text'); 611 $query .= " AND tbl.relname= $table";613 $query .= " AND UPPER(tbl.relname) = $table"; 612 614 } 613 615 $result = $db->queryCol($query); … … 684 686 } 685 687 688 list($schema, $table) = $this->splitTableSchema($table); 689 686 690 $table = $db->quoteIdentifier($table, true); 691 if (!empty($schema)) { 692 $table = $db->quoteIdentifier($schema, true) . '.' .$table; 693 } 687 694 $db->setLimit(1); 688 695 $result2 = $db->query("SELECT * FROM $table"); … … 715 722 } 716 723 724 list($schema, $table) = $this->splitTableSchema($table); 725 717 726 $table = $db->quote($table, 'text'); 718 $subquery = "SELECT indexrelid FROM pg_index, pg_class"; 719 $subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'"; 727 $subquery = "SELECT indexrelid 728 FROM pg_index 729 LEFT JOIN pg_class ON pg_class.oid = pg_index.indrelid 730 LEFT JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid 731 WHERE pg_class.relname = $table 732 AND indisunique != 't' 733 AND indisprimary != 't'"; 734 if (!empty($schema)) { 735 $subquery .= ' AND pg_namespace.nspname = '.$db->quote($schema, 'text'); 736 } 720 737 $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)"; 721 738 $indexes = $db->queryCol($query, 'text'); … … 739 756 740 757 // }}} 758 // {{{ dropConstraint() 759 760 /** 761 * drop existing constraint 762 * 763 * @param string $table name of table that should be used in method 764 * @param string $name name of the constraint to be dropped 765 * @param string $primary hint if the constraint is primary 766 * 767 * @return mixed MDB2_OK on success, a MDB2 error on failure 768 * @access public 769 */ 770 function dropConstraint($table, $name, $primary = false) 771 { 772 $db =& $this->getDBInstance(); 773 if (PEAR::isError($db)) { 774 return $db; 775 } 776 777 // is it an UNIQUE index? 778 $query = 'SELECT relname 779 FROM pg_class 780 WHERE oid IN ( 781 SELECT indexrelid 782 FROM pg_index, pg_class 783 WHERE pg_class.relname = '.$db->quote($table, 'text').' 784 AND pg_class.oid = pg_index.indrelid 785 AND indisunique = \'t\') 786 EXCEPT 787 SELECT conname 788 FROM pg_constraint, pg_class 789 WHERE pg_constraint.conrelid = pg_class.oid 790 AND relname = '. $db->quote($table, 'text'); 791 $unique = $db->queryCol($query, 'text'); 792 if (PEAR::isError($unique) || empty($unique)) { 793 // not an UNIQUE index, maybe a CONSTRAINT 794 return parent::dropConstraint($table, $name, $primary); 795 } 796 797 if (in_array($name, $unique)) { 798 return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true)); 799 } 800 $idxname = $db->getIndexName($name); 801 if (in_array($idxname, $unique)) { 802 return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true)); 803 } 804 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 805 $name . ' is not an existing constraint for table ' . $table, __FUNCTION__); 806 } 807 808 // }}} 741 809 // {{{ listTableConstraints() 742 810 … … 755 823 } 756 824 825 list($schema, $table) = $this->splitTableSchema($table); 826 757 827 $table = $db->quote($table, 'text'); 758 828 $query = 'SELECT conname 759 FROM pg_constraint, pg_class 760 WHERE pg_constraint.conrelid = pg_class.oid 761 AND relname = ' .$table; 829 FROM pg_constraint 830 LEFT JOIN pg_class ON pg_constraint.conrelid = pg_class.oid 831 LEFT JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid 832 WHERE relname = ' .$table; 833 if (!empty($schema)) { 834 $query .= ' AND pg_namespace.nspname = ' . $db->quote($schema, 'text'); 835 } 836 $query .= ' 837 UNION DISTINCT 838 SELECT relname 839 FROM pg_class 840 WHERE oid IN ( 841 SELECT indexrelid 842 FROM pg_index 843 LEFT JOIN pg_class ON pg_class.oid = pg_index.indrelid 844 LEFT JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid 845 WHERE pg_class.relname = '.$table.' 846 AND indisunique = \'t\''; 847 if (!empty($schema)) { 848 $query .= ' AND pg_namespace.nspname = ' . $db->quote($schema, 'text'); 849 } 850 $query .= ')'; 762 851 $constraints = $db->queryCol($query); 763 852 if (PEAR::isError($constraints)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/Manager/sqlite.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: sqlite.php ,v 1.74 2008/03/05 11:08:53 quipo Exp$46 // $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 221 221 * create a new table 222 222 * 223 * @param string $name Name of the database that should be created 224 * @param array $fields Associative array that contains the definition of each field of the new table 225 * @param array $options An associative array of table options 223 * @param string $name Name of the database that should be created 224 * @param array $fields Associative array that contains the definition 225 * of each field of the new table 226 * @param array $options An associative array of table options 227 * 226 228 * @return mixed MDB2_OK on success, a MDB2 error on failure 227 229 * @access public … … 243 245 continue; 244 246 } 245 //set actions to 'RESTRICT'if not set246 $fkdef['onupdate'] = empty($fkdef['onupdate']) ? 'RESTRICT': strtoupper($fkdef['onupdate']);247 $fkdef['ondelete'] = empty($fkdef['ondelete']) ? 'RESTRICT': strtoupper($fkdef['ondelete']);247 //set actions to default if not set 248 $fkdef['onupdate'] = empty($fkdef['onupdate']) ? $db->options['default_fk_action_onupdate'] : strtoupper($fkdef['onupdate']); 249 $fkdef['ondelete'] = empty($fkdef['ondelete']) ? $db->options['default_fk_action_ondelete'] : strtoupper($fkdef['ondelete']); 248 250 249 251 $trigger_names = array( … … 301 303 $null_values[] = $table_fields[$i] .' = NULL'; 302 304 } 303 $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL'; 305 $conditions2 = array(); 306 for ($i=0; $i<count($referenced_fields); $i++) { 307 $conditions2[] = 'NEW.'.$referenced_fields[$i] .' <> OLD.'.$referenced_fields[$i]; 308 } 309 $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL' 310 .' AND (' .implode(' OR ', $conditions2) .')'; 304 311 305 312 $cascade_action_update = 'UPDATE '.$name.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions); … … 332 339 } elseif ('NO ACTION' == $fkdef['onupdate']) { 333 340 $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update') . '; END;'; 334 } else { 335 //'RESTRICT' 341 } elseif ('RESTRICT' == $fkdef['onupdate']) { 336 342 $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . '; END;'; 337 343 } … … 344 350 } elseif ('NO ACTION' == $fkdef['ondelete']) { 345 351 $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete') . '; END;'; 346 } else { 347 //'RESTRICT' 352 } elseif ('RESTRICT' == $fkdef['ondelete']) { 348 353 $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . '; END;'; 349 354 } … … 900 905 901 906 $query = "SELECT name FROM sqlite_master WHERE type='trigger' AND sql NOT NULL"; 902 if ( !is_null($table)) {907 if (null !== $table) { 903 908 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 904 909 $query.= ' AND LOWER(tbl_name)='.$db->quote(strtolower($table), 'text'); … … 1160 1165 * @param string $fkname FOREIGN KEY constraint name 1161 1166 * @param string $referenced_table referenced table name 1167 * 1162 1168 * @return mixed MDB2_OK on success, a MDB2 error on failure 1163 1169 * @access private … … 1187 1193 } 1188 1194 1189 // } ]]1195 // }}} 1190 1196 // {{{ listTableConstraints() 1191 1197 -
trunk/roundcubemail/program/lib/MDB2/Driver/Native/Common.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Common.php ,v 1.2 2007/09/09 13:47:36 quipo Exp$45 // $Id: Common.php 242348 2007-09-09 13:47:36Z quipo $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Native/mssql.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mssql.php ,v 1.9 2006/06/18 21:59:05 lsmith Exp$45 // $Id: mssql.php 215004 2006-06-18 21:59:05Z lsmith $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Native/mysql.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysql.php ,v 1.9 2006/06/18 21:59:05 lsmith Exp$45 // $Id: mysql.php 215004 2006-06-18 21:59:05Z lsmith $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Native/mysqli.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysqli.php ,v 1.8 2006/06/18 21:59:05 lsmith Exp$45 // $Id: mysqli.php 215004 2006-06-18 21:59:05Z lsmith $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Native/pgsql.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: pgsql.php ,v 1.12 2006/07/15 13:07:15 lsmith Exp$45 // $Id: pgsql.php 216444 2006-07-15 13:07:15Z lsmith $ 46 46 47 47 require_once 'MDB2/Driver/Native/Common.php'; -
trunk/roundcubemail/program/lib/MDB2/Driver/Native/sqlite.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: sqlite.php ,v 1.9 2006/06/18 21:59:05 lsmith Exp$45 // $Id: sqlite.php 215004 2006-06-18 21:59:05Z lsmith $ 46 46 // 47 47 -
trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/Common.php
r1352 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Common.php ,v 1.42 2008/01/12 12:50:58 quipo Exp$45 // $Id: Common.php 273526 2009-01-14 15:01:21Z quipo $ 46 46 // 47 47 … … 77 77 /** 78 78 * Split the "[owner|schema].table" notation into an array 79 * 80 * @param string $table [schema and] table name 81 * 82 * @return array array(schema, table) 79 83 * @access private 80 84 */ -
trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/mssql.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mssql.php ,v 1.49 2008/02/17 15:30:57 quipo Exp$46 // $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 135 135 if (array_key_exists('column_default', $column)) { 136 136 $default = $column['column_default']; 137 if ( is_null($default) && $notnull) {137 if ((null === $default) && $notnull) { 138 138 $default = ''; 139 139 } elseif (strlen($default) > 4 … … 152 152 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 153 153 ); 154 if ( !is_null($length)) {154 if (null !== $length) { 155 155 $definition[0]['length'] = $length; 156 156 } 157 if ( !is_null($unsigned)) {157 if (null !== $unsigned) { 158 158 $definition[0]['unsigned'] = $unsigned; 159 159 } 160 if ( !is_null($fixed)) {160 if (null !== $fixed) { 161 161 $definition[0]['fixed'] = $fixed; 162 162 } 163 if ( $default !== false) {163 if (false !== $default) { 164 164 $definition[0]['default'] = $default; 165 165 } … … 223 223 $index_name_mdb2 = $db->getIndexName($index_name); 224 224 $result = $db->queryRow(sprintf($query, $index_name_mdb2)); 225 if (!PEAR::isError($result) && !is_null($result)) {225 if (!PEAR::isError($result) && (null !== $result)) { 226 226 // apply 'idxname_format' only if the query succeeded, otherwise 227 227 // fallback to the given $index_name, without transformation … … 321 321 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 322 322 $result = $db->queryRow(sprintf($query, $constraint_name_mdb2)); 323 if (!PEAR::isError($result) && !is_null($result)) {323 if (!PEAR::isError($result) && (null !== $result)) { 324 324 // apply 'idxname_format' only if the query succeeded, otherwise 325 325 // fallback to the given $index_name, without transformation -
trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/mysql.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysql.php ,v 1.79 2007/11/25 13:38:29 quipo Exp$45 // $Id: mysql.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 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 } … … 132 132 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 133 133 ); 134 if ( !is_null($length)) {134 if (null !== $length) { 135 135 $definition[0]['length'] = $length; 136 136 } 137 if ( !is_null($unsigned)) {137 if (null !== $unsigned) { 138 138 $definition[0]['unsigned'] = $unsigned; 139 139 } 140 if ( !is_null($fixed)) {140 if (null !== $fixed) { 141 141 $definition[0]['fixed'] = $fixed; 142 142 } … … 147 147 $definition[0]['autoincrement'] = $autoincrement; 148 148 } 149 if ( !is_null($collate)) {149 if (null !== $collate) { 150 150 $definition[0]['collate'] = $collate; 151 151 $definition[0]['charset'] = $charset; … … 193 193 $index_name_mdb2 = $db->getIndexName($index_name); 194 194 $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); 195 if (!PEAR::isError($result) && !is_null($result)) {195 if (!PEAR::isError($result) && (null !== $result)) { 196 196 // apply 'idxname_format' only if the query succeeded, otherwise 197 197 // fallback to the given $index_name, without transformation … … 270 270 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 271 271 $result = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2))); 272 if (!PEAR::isError($result) && !is_null($result)) {272 if (!PEAR::isError($result) && (null !== $result)) { 273 273 // apply 'idxname_format' only if the query succeeded, otherwise 274 274 // fallback to the given $index_name, without transformation … … 311 311 if ($row['non_unique']) { 312 312 //FOREIGN KEY? 313 $query = 'SHOW CREATE TABLE '. $db->escape($table); 314 $constraint = $db->queryOne($query, 'text', 1); 315 if (!PEAR::isError($constraint) && !empty($constraint)) { 316 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 317 if ($db->options['field_case'] == CASE_LOWER) { 318 $constraint = strtolower($constraint); 319 } else { 320 $constraint = strtoupper($constraint); 321 } 322 } 323 $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 324 if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 325 //fallback to original constraint name 326 $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 327 } 328 if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 329 $definition['foreign'] = true; 330 $column_names = explode(',', $matches[1]); 331 $referenced_cols = explode(',', $matches[3]); 332 $definition['references'] = array( 333 'table' => $matches[2], 334 'fields' => array(), 335 ); 336 $colpos = 1; 337 foreach ($column_names as $column_name) { 338 $definition['fields'][trim($column_name)] = array( 339 'position' => $colpos++ 340 ); 341 } 342 $colpos = 1; 343 foreach ($referenced_cols as $column_name) { 344 $definition['references']['fields'][trim($column_name)] = array( 345 'position' => $colpos++ 346 ); 347 } 348 $definition['onupdate'] = 'NO ACTION'; 349 $definition['ondelete'] = 'NO ACTION'; 350 $definition['match'] = 'SIMPLE'; 351 return $definition; 352 } 353 } 354 355 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 356 $constraint_name . ' is not an existing table constraint', __FUNCTION__); 313 return $this->_getTableFKConstraintDefinition($table, $constraint_name_original, $definition); 357 314 } 358 315 if ($row['key_name'] == 'PRIMARY') { … … 380 337 $result->free(); 381 338 if (empty($definition['fields'])) { 382 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 339 return $this->_getTableFKConstraintDefinition($table, $constraint_name_original, $definition); 340 } 341 return $definition; 342 } 343 344 // }}} 345 // {{{ _getTableFKConstraintDefinition() 346 347 /** 348 * Get the FK definition from the CREATE TABLE statement 349 * 350 * @param string $table table name 351 * @param string $constraint_name constraint name 352 * @param array $definition default values for constraint definition 353 * 354 * @return array|PEAR_Error 355 * @access private 356 */ 357 function _getTableFKConstraintDefinition($table, $constraint_name, $definition) 358 { 359 $db =& $this->getDBInstance(); 360 if (PEAR::isError($db)) { 361 return $db; 362 } 363 $query = 'SHOW CREATE TABLE '. $db->escape($table); 364 $constraint = $db->queryOne($query, 'text', 1); 365 if (!PEAR::isError($constraint) && !empty($constraint)) { 366 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 367 if ($db->options['field_case'] == CASE_LOWER) { 368 $constraint = strtolower($constraint); 369 } else { 370 $constraint = strtoupper($constraint); 371 } 372 } 373 $constraint_name_original = $constraint_name; 374 $constraint_name = $db->getIndexName($constraint_name); 375 $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 376 if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 377 //fallback to original constraint name 378 $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 379 } 380 if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 381 $definition['foreign'] = true; 382 $column_names = explode(',', $matches[1]); 383 $referenced_cols = explode(',', $matches[3]); 384 $definition['references'] = array( 385 'table' => $matches[2], 386 'fields' => array(), 387 ); 388 $colpos = 1; 389 foreach ($column_names as $column_name) { 390 $definition['fields'][trim($column_name)] = array( 391 'position' => $colpos++ 392 ); 393 } 394 $colpos = 1; 395 foreach ($referenced_cols as $column_name) { 396 $definition['references']['fields'][trim($column_name)] = array( 397 'position' => $colpos++ 398 ); 399 } 400 $definition['onupdate'] = 'NO ACTION'; 401 $definition['ondelete'] = 'NO ACTION'; 402 $definition['match'] = 'SIMPLE'; 403 return $definition; 404 } 405 } 406 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 383 407 $constraint_name . ' is not an existing table constraint', __FUNCTION__); 384 }385 return $definition;386 408 } 387 409 -
trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/mysqli.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: mysqli.php ,v 1.69 2007/11/25 13:38:29 quipo Exp$45 // $Id: mysqli.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 // 47 47 … … 168 168 if (array_key_exists('default', $column)) { 169 169 $default = $column['default']; 170 if ( is_null($default) && $notnull) {170 if ((null === $default) && $notnull) { 171 171 $default = ''; 172 172 } … … 186 186 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 187 187 ); 188 if ( !is_null($length)) {188 if (null !== $length) { 189 189 $definition[0]['length'] = $length; 190 190 } 191 if ( !is_null($unsigned)) {191 if (null !== $unsigned) { 192 192 $definition[0]['unsigned'] = $unsigned; 193 193 } 194 if ( !is_null($fixed)) {194 if (null !== $fixed) { 195 195 $definition[0]['fixed'] = $fixed; 196 196 } … … 201 201 $definition[0]['autoincrement'] = $autoincrement; 202 202 } 203 if ( !is_null($collate)) {203 if (null !== $collate) { 204 204 $definition[0]['collate'] = $collate; 205 205 $definition[0]['charset'] = $charset; … … 247 247 $index_name_mdb2 = $db->getIndexName($index_name); 248 248 $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); 249 if (!PEAR::isError($result) && !is_null($result)) {249 if (!PEAR::isError($result) && (null !== $result)) { 250 250 // apply 'idxname_format' only if the query succeeded, otherwise 251 251 // fallback to the given $index_name, without transformation … … 324 324 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 325 325 $result = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2))); 326 if (!PEAR::isError($result) && !is_null($result)) {326 if (!PEAR::isError($result) && (null !== $result)) { 327 327 // apply 'idxname_format' only if the query succeeded, otherwise 328 328 // fallback to the given $index_name, without transformation … … 365 365 if ($row['non_unique']) { 366 366 //FOREIGN KEY? 367 $query = 'SHOW CREATE TABLE '. $db->escape($table); 368 $constraint = $db->queryOne($query, 'text', 1); 369 if (!PEAR::isError($constraint) && !empty($constraint)) { 370 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 371 if ($db->options['field_case'] == CASE_LOWER) { 372 $constraint = strtolower($constraint); 373 } else { 374 $constraint = strtoupper($constraint); 375 } 376 } 377 $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 378 if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 379 //fallback to original constraint name 380 $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 381 } 382 if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 383 $definition['foreign'] = true; 384 $column_names = explode(',', $matches[1]); 385 $referenced_cols = explode(',', $matches[3]); 386 $definition['references'] = array( 387 'table' => $matches[2], 388 'fields' => array(), 389 ); 390 $colpos = 1; 391 foreach ($column_names as $column_name) { 392 $definition['fields'][trim($column_name)] = array( 393 'position' => $colpos++ 394 ); 395 } 396 $colpos = 1; 397 foreach ($referenced_cols as $column_name) { 398 $definition['references']['fields'][trim($column_name)] = array( 399 'position' => $colpos++ 400 ); 401 } 402 $definition['onupdate'] = 'NO ACTION'; 403 $definition['ondelete'] = 'NO ACTION'; 404 $definition['match'] = 'SIMPLE'; 405 return $definition; 406 } 407 } 408 409 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 410 $constraint_name . ' is not an existing table constraint', __FUNCTION__); 367 return $this->_getTableFKConstraintDefinition($table, $constraint_name_original, $definition); 411 368 } 412 369 if ($row['key_name'] == 'PRIMARY') { … … 434 391 $result->free(); 435 392 if (empty($definition['fields'])) { 436 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 393 return $this->_getTableFKConstraintDefinition($table, $constraint_name_original, $definition); 394 } 395 return $definition; 396 } 397 398 // }}} 399 // {{{ _getTableFKConstraintDefinition() 400 401 /** 402 * Get the FK definition from the CREATE TABLE statement 403 * 404 * @param string $table table name 405 * @param string $constraint_name constraint name 406 * @param array $definition default values for constraint definition 407 * 408 * @return array|PEAR_Error 409 * @access private 410 */ 411 function _getTableFKConstraintDefinition($table, $constraint_name, $definition) 412 { 413 $db =& $this->getDBInstance(); 414 if (PEAR::isError($db)) { 415 return $db; 416 } 417 $query = 'SHOW CREATE TABLE '. $db->escape($table); 418 $constraint = $db->queryOne($query, 'text', 1); 419 if (!PEAR::isError($constraint) && !empty($constraint)) { 420 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 421 if ($db->options['field_case'] == CASE_LOWER) { 422 $constraint = strtolower($constraint); 423 } else { 424 $constraint = strtoupper($constraint); 425 } 426 } 427 $constraint_name_original = $constraint_name; 428 $constraint_name = $db->getIndexName($constraint_name); 429 $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 430 if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 431 //fallback to original constraint name 432 $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i'; 433 } 434 if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) { 435 $definition['foreign'] = true; 436 $column_names = explode(',', $matches[1]); 437 $referenced_cols = explode(',', $matches[3]); 438 $definition['references'] = array( 439 'table' => $matches[2], 440 'fields' => array(), 441 ); 442 $colpos = 1; 443 foreach ($column_names as $column_name) { 444 $definition['fields'][trim($column_name)] = array( 445 'position' => $colpos++ 446 ); 447 } 448 $colpos = 1; 449 foreach ($referenced_cols as $column_name) { 450 $definition['references']['fields'][trim($column_name)] = array( 451 'position' => $colpos++ 452 ); 453 } 454 $definition['onupdate'] = 'NO ACTION'; 455 $definition['ondelete'] = 'NO ACTION'; 456 $definition['match'] = 'SIMPLE'; 457 return $definition; 458 } 459 } 460 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 437 461 $constraint_name . ' is not an existing table constraint', __FUNCTION__); 438 }439 return $definition;440 462 } 441 463 -
trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/pgsql.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: pgsql.php ,v 1.70 2008/03/13 20:38:09 quipo Exp$46 // $Id: pgsql.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 48 48 require_once 'MDB2/Driver/Reverse/Common.php'; … … 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 $pattern = '/ (\'.*\')::[\w ]+$/i';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 } … … 300 301 LEFT JOIN pg_class t2 ON c.confrelid = t2.oid 301 302 WHERE c.conname = %s 302 AND t.relname = " . $db->quote($table, 'text');303 AND t.relname = " . $db->quote($table, 'text'); 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); … … 311 312 return $row; 312 313 } 313 314 $uniqueIndex = false; 314 315 if (empty($row)) { 315 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 316 $constraint_name . ' is not an existing table constraint', __FUNCTION__); 316 // We might be looking for a UNIQUE index that was not created 317 // as a constraint but should be treated as such. 318 $query = 'SELECT relname AS constraint_name, 319 indkey, 320 0 AS "check", 321 0 AS "foreign", 322 0 AS "primary", 323 1 AS "unique", 324 0 AS deferrable, 325 0 AS initiallydeferred, 326 NULL AS references_table, 327 NULL AS onupdate, 328 NULL AS ondelete, 329 NULL AS match 330 FROM pg_index, pg_class 331 WHERE pg_class.oid = pg_index.indexrelid 332 AND indisunique = \'t\' 333 AND pg_class.relname = %s'; 334 $constraint_name_mdb2 = $db->getIndexName($constraint_name); 335 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 336 if (PEAR::isError($row) || empty($row)) { 337 // fallback to the given $index_name, without transformation 338 $constraint_name_mdb2 = $constraint_name; 339 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 340 } 341 if (PEAR::isError($row)) { 342 return $row; 343 } 344 if (empty($row)) { 345 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 346 $constraint_name . ' is not an existing table constraint', __FUNCTION__); 347 } 348 $uniqueIndex = true; 317 349 } 318 350 … … 336 368 ); 337 369 370 if ($uniqueIndex) { 371 $db->loadModule('Manager', null, true); 372 $columns = $db->manager->listTableFields($table_name); 373 $index_column_numbers = explode(' ', $row['indkey']); 374 $colpos = 1; 375 foreach ($index_column_numbers as $number) { 376 $definition['fields'][$columns[($number - 1)]] = array( 377 'position' => $colpos++, 378 'sorting' => 'ascending', 379 ); 380 } 381 return $definition; 382 } 383 338 384 $query = 'SELECT a.attname 339 385 FROM pg_constraint c … … 342 388 WHERE c.conname = %s 343 389 AND t.relname = ' . $db->quote($table, 'text'); 344 $constraint_name_mdb2 = $db->getIndexName($constraint_name);345 390 $fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null); 346 391 if (PEAR::isError($fields)) { … … 362 407 WHERE c.conname = %s 363 408 AND t.relname = ' . $db->quote($definition['references']['table'], 'text'); 364 $constraint_name_mdb2 = $db->getIndexName($constraint_name);365 409 $foreign_fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null); 366 410 if (PEAR::isError($foreign_fields)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/sqlite.php
r1352 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: sqlite.php ,v 1.79 2008/03/05 11:08:53 quipo Exp$46 // $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 58 58 class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common 59 59 { 60 /** 61 * Remove SQL comments from the field definition 62 * 63 * @access private 64 */ 65 function _removeComments($sql) { 66 $lines = explode("\n", $sql); 67 foreach ($lines as $k => $line) { 68 $pieces = explode('--', $line); 69 if (count($pieces) > 1 && (substr_count($pieces[0], '\'') % 2) == 0) { 70 $lines[$k] = substr($line, 0, strpos($line, '--')); 71 } 72 } 73 return implode("\n", $lines); 74 } 75 76 /** 77 * 78 */ 60 79 function _getTableColumns($sql) 61 80 { … … 69 88 // replace the decimal length-places-separator with a colon 70 89 $column_def = preg_replace('/(\d),(\d)/', '\1:\2', $column_def); 71 $column_sql = split(',', $column_def); 90 $column_def = $this->_removeComments($column_def); 91 $column_sql = explode(',', $column_def); 72 92 $columns = array(); 73 93 $count = count($column_sql); … … 76 96 'unexpected empty table column definition list', __FUNCTION__); 77 97 } 78 $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( UNSIGNED)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?$/i';98 $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i'; 79 99 $regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i'; 80 100 for ($i=0, $j=0; $i<$count; ++$i) { … … 94 114 $columns[$j]['decimal'] = $matches[6]; 95 115 } 96 if (isset($matches[ 7]) && strlen($matches[7])) {116 if (isset($matches[8]) && strlen($matches[8])) { 97 117 $columns[$j]['unsigned'] = true; 98 118 } 99 if (isset($matches[ 8]) && strlen($matches[8])) {119 if (isset($matches[9]) && strlen($matches[9])) { 100 120 $columns[$j]['autoincrement'] = true; 101 121 } 102 if (isset($matches[1 0]) && strlen($matches[10])) {103 $default = $matches[1 0];122 if (isset($matches[12]) && strlen($matches[12])) { 123 $default = $matches[12]; 104 124 if (strlen($default) && $default[0]=="'") { 105 125 $default = str_replace("''", "'", substr($default, 1, strlen($default)-2)); … … 110 130 $columns[$j]['default'] = $default; 111 131 } 112 if (isset($matches[11]) && strlen($matches[11])) { 113 $columns[$j]['notnull'] = ($matches[11] === ' NOT NULL'); 132 if (isset($matches[7]) && strlen($matches[7])) { 133 $columns[$j]['notnull'] = ($matches[7] === ' NOT NULL'); 134 } else if (isset($matches[9]) && strlen($matches[9])) { 135 $columns[$j]['notnull'] = ($matches[9] === ' NOT NULL'); 136 } else if (isset($matches[13]) && strlen($matches[13])) { 137 $columns[$j]['notnull'] = ($matches[13] === ' NOT NULL'); 114 138 } 115 139 ++$j; … … 178 202 if (array_key_exists('default', $column)) { 179 203 $default = $column['default']; 180 if ( is_null($default) && $notnull) {204 if ((null === $default) && $notnull) { 181 205 $default = ''; 182 206 } … … 191 215 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 192 216 ); 193 if ( !is_null($length)) {217 if (null !== $length) { 194 218 $definition[0]['length'] = $length; 195 219 } 196 if ( !is_null($unsigned)) {220 if (null !== $unsigned) { 197 221 $definition[0]['unsigned'] = $unsigned; 198 222 } 199 if ( !is_null($fixed)) {223 if (null !== $fixed) { 200 224 $definition[0]['fixed'] = $fixed; 201 225 } … … 277 301 $end_pos = strrpos($sql, ')'); 278 302 $column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1); 279 $column_names = split(',', $column_names);303 $column_names = explode(',', $column_names); 280 304 281 305 if (preg_match("/^create unique/", $sql)) { … … 385 409 $definition['primary'] = true; 386 410 $definition['fields'] = array(); 387 $column_names = split(',', $tmp[1]);411 $column_names = explode(',', $tmp[1]); 388 412 $colpos = 1; 389 413 foreach ($column_names as $column_name) { … … 397 421 $definition['primary'] = true; 398 422 $definition['fields'] = array(); 399 $column_names = split(',', $tmp[1]);423 $column_names = explode(',', $tmp[1]); 400 424 $colpos = 1; 401 425 foreach ($column_names as $column_name) { … … 427 451 $definition['ondelete'] = 'NO ACTION'; 428 452 $definition['references']['table'] = $tmp[2]; 429 $column_names = split(',', $tmp[1]);453 $column_names = explode(',', $tmp[1]); 430 454 $colpos = 1; 431 455 foreach ($column_names as $column_name) { … … 434 458 ); 435 459 } 436 $referenced_cols = split(',', $tmp[3]);460 $referenced_cols = explode(',', $tmp[3]); 437 461 $colpos = 1; 438 462 foreach ($referenced_cols as $column_name) { … … 464 488 $end_pos = strrpos($sql, ')'); 465 489 $column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1); 466 $column_names = split(',', $column_names);490 $column_names = explode(',', $column_names); 467 491 468 492 if (!preg_match("/^create unique/", $sql)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/mssql.php
r3039 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mssql.php ,v 1.174 2008/03/08 14:18:39 quipo Exp$46 // $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 // {{{ Class MDB2_Driver_mssql … … 114 114 function errorInfo($error = null, $connection = null) 115 115 { 116 if ( is_null($connection)) {116 if (null === $connection) { 117 117 $connection = $this->connection; 118 118 } … … 127 127 } 128 128 $native_msg = @mssql_get_last_message(); 129 if ( is_null($error)) {129 if (null === $error) { 130 130 static $ecode_map; 131 131 if (empty($ecode_map)) { … … 204 204 205 205 // }}} 206 // {{{ escape() 207 208 /** 209 * Quotes a string so it can be safely used in a query. It will quote 210 * the text so it can safely be used within a query. 211 * 212 * @param string $text the input string to quote 213 * @param bool $escape_wildcards flag 214 * 215 * @return string quoted string 216 * @access public 217 */ 218 function escape($text, $escape_wildcards = false) 219 { 220 $text = parent::escape($text, $escape_wildcards); 221 // http://pear.php.net/bugs/bug.php?id=16118 222 // http://support.microsoft.com/kb/164291 223 return preg_replace("/\\\\(\r\n|\r|\n)/", '\\\\$1', $text); 224 } 225 226 // }}} 206 227 // {{{ beginTransaction() 207 228 … … 209 230 * Start a transaction or set a savepoint. 210 231 * 211 * @param stringname of a savepoint to set212 * @return mixed MDB2_OK on success, a MDB2 error on failure213 * 214 * @access public232 * @param string $savepoint name of a savepoint to set 233 * 234 * @return mixed MDB2_OK on success, a MDB2 error on failure 235 * @access public 215 236 */ 216 237 function beginTransaction($savepoint = null) 217 238 { 218 239 $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 219 if ( !is_null($savepoint)) {240 if (null !== $savepoint) { 220 241 if (!$this->in_transaction) { 221 242 return $this->raiseError(MDB2_ERROR_INVALID, null, null, … … 224 245 $query = 'SAVE TRANSACTION '.$savepoint; 225 246 return $this->_doQuery($query, true); 226 } elseif ($this->in_transaction) { 247 } 248 if ($this->in_transaction) { 227 249 return MDB2_OK; //nothing to do 228 250 } … … 248 270 * transaction is implicitly started after committing the pending changes. 249 271 * 250 * @param stringname of a savepoint to release251 * @return mixed MDB2_OK on success, a MDB2 error on failure252 * 272 * @param string $savepoint name of a savepoint to release 273 * 274 * @return mixed MDB2_OK on success, a MDB2 error on failure 253 275 * @access public 254 276 */ … … 260 282 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 261 283 } 262 if ( !is_null($savepoint)) {284 if (null !== $savepoint) { 263 285 return MDB2_OK; 264 286 } … … 281 303 * transaction is implicitly started after canceling the pending changes. 282 304 * 283 * @param stringname of a savepoint to rollback to284 * @return mixed MDB2_OK on success, a MDB2 error on failure285 * 286 * @access public305 * @param string $savepoint name of a savepoint to rollback to 306 * 307 * @return mixed MDB2_OK on success, a MDB2 error on failure 308 * @access public 287 309 */ 288 310 function rollback($savepoint = null) … … 293 315 'rollback cannot be done changes are auto committed', __FUNCTION__); 294 316 } 295 if ( !is_null($savepoint)) {317 if (null !== $savepoint) { 296 318 $query = 'ROLLBACK TRANSACTION '.$savepoint; 297 319 return $this->_doQuery($query, true); … … 312 334 * do the grunt work of the connect 313 335 * 336 * @param string $username 337 * @param string $password 338 * @param boolean $persistent 339 * 314 340 * @return connection on success or MDB2 Error Object on failure 315 341 * @access protected … … 317 343 function _doConnect($username, $password, $persistent = false) 318 344 { 319 if (!PEAR::loadExtension($this->phptype) && !PEAR::loadExtension('sybase_ct')) { 345 if ( !PEAR::loadExtension($this->phptype) 346 && !PEAR::loadExtension('sybase_ct') 347 && !PEAR::loadExtension('odbtp') 348 && !function_exists('mssql_connect') 349 ) { 320 350 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 321 351 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__); … … 326 356 $username ? $username : null, 327 357 $password ? $password : null, 328 );358 ); 329 359 if ($this->dsn['port']) { 330 360 $params[0].= ((substr(PHP_OS, 0, 3) == 'WIN') ? ',' : ':').$this->dsn['port']; 331 361 } 332 362 if (!$persistent) { 333 if (isset($this->dsn['new_link']) 334 && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true) 335 ) { 363 if ($this->_isNewLinkSet()) { 336 364 $params[] = true; 337 365 } else { … … 350 378 @mssql_query('SET ANSI_NULL_DFLT_ON ON', $connection); 351 379 352 /*380 /* 353 381 if (!empty($this->dsn['charset'])) { 354 382 $result = $this->setCharset($this->dsn['charset'], $connection); … … 357 385 } 358 386 } 359 */ 360 361 if ((bool)ini_get('mssql.datetimeconvert')) { 362 @ini_set('mssql.datetimeconvert', '0'); 363 } 364 365 if (empty($this->dsn['disable_iso_date'])) { 366 @mssql_query('SET DATEFORMAT ymd', $connection); 367 } 368 369 return $connection; 387 */ 388 389 if ((bool)ini_get('mssql.datetimeconvert')) { 390 // his isn't the most elegant way of doing it but it prevents from 391 // breaking anything thus preserves BC. Bug #11849 392 if (isset($this->options['datetimeconvert']) && (bool)$this->options['datetimeconvert'] !== false) { 393 @ini_set('mssql.datetimeconvert', '1'); 394 } else { 395 @ini_set('mssql.datetimeconvert', '0'); 396 } 397 } 398 399 if (empty($this->dsn['disable_iso_date'])) { 400 @mssql_query('SET DATEFORMAT ymd', $connection); 401 } 402 403 return $connection; 370 404 } 371 405 … … 483 517 484 518 if (!$this->opened_persistent || $force) { 485 @mssql_close($this->connection); 486 } 519 $ok = @mssql_close($this->connection); 520 if (!$ok) { 521 return $this->raiseError(MDB2_ERROR_DISCONNECT_FAILED, 522 null, null, null, __FUNCTION__); 523 } 524 } 525 } else { 526 return false; 487 527 } 488 528 return parent::disconnect($force); … … 552 592 } 553 593 554 if ( is_null($connection)) {594 if (null === $connection) { 555 595 $connection = $this->getConnection(); 556 596 if (PEAR::isError($connection)) { … … 558 598 } 559 599 } 560 if ( is_null($database_name)) {600 if (null === $database_name) { 561 601 $database_name = $this->database_name; 562 602 } … … 597 637 function _affectedRows($connection, $result = null) 598 638 { 599 if ( is_null($connection)) {639 if (null === $connection) { 600 640 $connection = $this->getConnection(); 601 641 if (PEAR::isError($connection)) { … … 787 827 { 788 828 $server_info = $this->getServerVersion(); 789 if (is_array($server_info) && !is_null($server_info['major'])829 if (is_array($server_info) && (null !== $server_info['major']) 790 830 && $server_info['major'] >= 8 791 831 ) { … … 793 833 } else { 794 834 $query = "SELECT @@IDENTITY"; 795 if ( !is_null($table)) {835 if (null !== $table) { 796 836 $query .= ' FROM '.$this->quoteIdentifier($table, true); 797 837 } … … 850 890 * Fetch a row and insert the data into an existing array. 851 891 * 852 * @param int $fetchmode how the array data should be indexed 853 * @param int $rownum number of the row where the data can be found 892 * @param int $fetchmode how the array data should be indexed 893 * @param int $rownum number of the row where the data can be found 894 * 854 895 * @return int data array on success, a MDB2 error on failure 855 896 * @access public … … 861 902 return $null; 862 903 } 863 if ( !is_null($rownum)) {904 if (null !== $rownum) { 864 905 $seek = $this->seek($rownum); 865 906 if (PEAR::isError($seek)) { … … 881 922 } 882 923 if (!$row) { 883 if ( $this->result === false) {924 if (false === $this->result) { 884 925 $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 885 926 'resultset has already been freed', __FUNCTION__); … … 912 953 $row = (object) $row; 913 954 } else { 914 $row = new $object_class($row); 955 $rowObj = new $object_class($row); 956 $row = $rowObj; 915 957 } 916 958 } … … 961 1003 { 962 1004 $cols = @mssql_num_fields($this->result); 963 if ( is_null($cols)) {964 if ( $this->result === false) {1005 if (null === $cols) { 1006 if (false === $this->result) { 965 1007 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 966 1008 'resultset has already been freed', __FUNCTION__); 967 } elseif (is_null($this->result)) { 1009 } 1010 if (null === $this->result) { 968 1011 return count($this->types); 969 1012 } … … 985 1028 function nextResult() 986 1029 { 987 if ( $this->result === false) {1030 if (false === $this->result) { 988 1031 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 989 1032 'resultset has already been freed', __FUNCTION__); 990 } elseif (is_null($this->result)) { 1033 } 1034 if (null === $this->result) { 991 1035 return false; 992 1036 } … … 1007 1051 if (is_resource($this->result) && $this->db->connection) { 1008 1052 $free = @mssql_free_result($this->result); 1009 if ( $free === false) {1053 if (false === $free) { 1010 1054 return $this->db->raiseError(null, null, null, 1011 1055 'Could not free result', __FUNCTION__); … … 1036 1080 * Seek to a specific row in a result set 1037 1081 * 1038 * @param int $rownum number of the row where the data can be found 1082 * @param int $rownum number of the row where the data can be found 1083 * 1039 1084 * @return mixed MDB2_OK on success, a MDB2 error on failure 1040 1085 * @access public … … 1043 1088 { 1044 1089 if ($this->rownum != ($rownum - 1) && !@mssql_data_seek($this->result, $rownum)) { 1045 if ( $this->result === false) {1090 if (false === $this->result) { 1046 1091 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1047 1092 'resultset has already been freed', __FUNCTION__); 1048 } elseif (is_null($this->result)) { 1093 } 1094 if (null === $this->result) { 1049 1095 return MDB2_OK; 1050 1096 } … … 1086 1132 { 1087 1133 $rows = @mssql_num_rows($this->result); 1088 if ( is_null($rows)) {1089 if ( $this->result === false) {1134 if (null === $rows) { 1135 if (false === $this->result) { 1090 1136 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1091 1137 'resultset has already been freed', __FUNCTION__); 1092 } elseif (is_null($this->result)) { 1138 } 1139 if (null === $this->result) { 1093 1140 return 0; 1094 1141 } … … 1097 1144 } 1098 1145 if ($this->limit) { 1099 $rows -= $this->limit -1 + $this->offset; 1146 $rows -= $this->offset; 1147 if ($rows > $this->limit + 1) { 1148 $rows = $this->limit + 1; 1149 } 1100 1150 if ($rows < 0) { 1101 1151 $rows = 0; -
trunk/roundcubemail/program/lib/MDB2/Driver/mysql.php
r3039 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mysql.php ,v 1.208 2008/03/13 03:31:55 afz Exp$46 // $Id: mysql.php 292659 2009-12-26 17:31:01Z quipo $ 47 47 // 48 48 … … 338 338 register_shutdown_function('MDB2_closeOpenTransactions'); 339 339 } 340 $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1';340 $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0'; 341 341 $result =& $this->_doQuery($query, true); 342 342 if (PEAR::isError($result)) { … … 391 391 } 392 392 if (!$this->start_transaction) { 393 $query = 'SET AUTOCOMMIT = 0';393 $query = 'SET AUTOCOMMIT = 1'; 394 394 $result =& $this->_doQuery($query, true); 395 395 if (PEAR::isError($result)) { … … 437 437 } 438 438 if (!$this->start_transaction) { 439 $query = 'SET AUTOCOMMIT = 0';439 $query = 'SET AUTOCOMMIT = 1'; 440 440 $result =& $this->_doQuery($query, true); 441 441 if (PEAR::isError($result)) { … … 502 502 503 503 $params = array(); 504 if ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix') { 504 $unix = ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix'); 505 if (empty($this->dsn['hostspec'])) { 506 $this->dsn['hostspec'] = $unix ? '' : 'localhost'; 507 } 508 if ($this->dsn['hostspec']) { 509 $params[0] = $this->dsn['hostspec'] . ($this->dsn['port'] ? ':' . $this->dsn['port'] : ''); 510 } else { 505 511 $params[0] = ':' . $this->dsn['socket']; 506 } else {507 $params[0] = $this->dsn['hostspec'] ? $this->dsn['hostspec']508 : 'localhost';509 if ($this->dsn['port']) {510 $params[0].= ':' . $this->dsn['port'];511 }512 512 } 513 513 $params[] = $username ? $username : null; 514 514 $params[] = $password ? $password : null; 515 515 if (!$persistent) { 516 if (isset($this->dsn['new_link']) 517 && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true) 518 ) { 516 if ($this->_isNewLinkSet()) { 519 517 $params[] = true; 520 518 } else { … … 626 624 $charset = array_pop($charset); 627 625 } 626 $client_info = mysql_get_client_info(); 627 if (function_exists('mysql_set_charset') && version_compare($client_info, '5.0.6')) { 628 if (!$result = mysql_set_charset($charset, $connection)) { 629 $err =& $this->raiseError(null, null, null, 630 'Could not set client character set', __FUNCTION__); 631 return $err; 632 } 633 return $result; 634 } 628 635 $query = "SET NAMES '".mysql_real_escape_string($charset, $connection)."'"; 629 636 if (!is_null($collation)) { 630 $query .= " COLLATE '".mysql i_real_escape_string($connection, $collation)."'";637 $query .= " COLLATE '".mysql_real_escape_string($collation, $connection)."'"; 631 638 } 632 639 return $this->_doQuery($query, true, $connection); … … 688 695 689 696 if (!$this->opened_persistent || $force) { 690 @mysql_close($this->connection); 691 } 697 $ok = @mysql_close($this->connection); 698 if (!$ok) { 699 return $this->raiseError(MDB2_ERROR_DISCONNECT_FAILED, 700 null, null, null, __FUNCTION__); 701 } 702 } 703 } else { 704 return false; 692 705 } 693 706 return parent::disconnect($force); … … 781 794 ? 'mysql_query' : 'mysql_unbuffered_query'; 782 795 $result = @$function($query, $connection); 783 if (!$result ) {796 if (!$result && 0 !== mysql_errno($connection)) { 784 797 $err =& $this->raiseError(null, null, null, 785 798 'Could not execute statement', __FUNCTION__); … … 1022 1035 function &prepare($query, $types = null, $result_types = null, $lobs = array()) 1023 1036 { 1037 // connect to get server capabilities (http://pear.php.net/bugs/16147) 1038 $connection = $this->getConnection(); 1039 if (PEAR::isError($connection)) { 1040 return $connection; 1041 } 1042 1024 1043 if ($this->options['emulate_prepared'] 1025 1044 || $this->supported['prepared_statements'] !== true … … 1100 1119 } 1101 1120 } 1102 $connection = $this->getConnection(); 1103 if (PEAR::isError($connection)) { 1104 return $connection; 1105 } 1121 1106 1122 static $prep_statement_counter = 1; 1107 1123 $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand())); … … 1125 1141 * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 1126 1142 * query, except that if there is already a row in the table with the same 1127 * key field values, the REPLACE query just updates its values instead of 1128 * inserting a new row. 1143 * key field values, the old row is deleted before the new row is inserted. 1129 1144 * 1130 1145 * The REPLACE type of query does not make part of the SQL standards. Since … … 1184 1199 * Default: 0 1185 1200 * 1201 * @see http://dev.mysql.com/doc/refman/5.0/en/replace.html 1186 1202 * @return mixed MDB2_OK on success, a MDB2 error on failure 1187 1203 */ … … 1394 1410 $row = (object) $row; 1395 1411 } else { 1396 $row = new $object_class($row); 1412 $rowObj = new $object_class($row); 1413 $row = $rowObj; 1397 1414 } 1398 1415 } … … 1556 1573 return $rows; 1557 1574 } 1575 1576 // }}} 1558 1577 } 1559 1578 … … 1574 1593 * @param mixed $result_class string which specifies which result class to use 1575 1594 * @param mixed $result_wrap_class string which specifies which class to wrap results in 1576 * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure 1595 * 1596 * @return mixed MDB2_Result or integer (affected rows) on success, 1597 * a MDB2 error on failure 1577 1598 * @access private 1578 1599 */ … … 1603 1624 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__); 1604 1625 } 1626 $close = false; 1605 1627 $value = $this->values[$parameter]; 1606 1628 $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null; -
trunk/roundcubemail/program/lib/MDB2/Driver/mysqli.php
r3039 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: mysqli.php ,v 1.188 2008/03/13 03:31:55 afz Exp$46 // $Id: mysqli.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 190 190 $native_msg = @mysqli_connect_error(); 191 191 } 192 if ( is_null($error)) {192 if (null === $error) { 193 193 static $ecode_map; 194 194 if (empty($ecode_map)) { … … 321 321 $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 322 322 $this->_getServerCapabilities(); 323 if ( !is_null($savepoint)) {323 if (null !== $savepoint) { 324 324 if (!$this->supports('savepoints')) { 325 325 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, … … 332 332 $query = 'SAVEPOINT '.$savepoint; 333 333 return $this->_doQuery($query, true); 334 } elseif ($this->in_transaction) { 334 } 335 if ($this->in_transaction) { 335 336 return MDB2_OK; //nothing to do 336 337 } 337 $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1';338 $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0'; 338 339 $result =& $this->_doQuery($query, true); 339 340 if (PEAR::isError($result)) { … … 365 366 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 366 367 } 367 if ( !is_null($savepoint)) {368 if (null !== $savepoint) { 368 369 if (!$this->supports('savepoints')) { 369 370 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, … … 388 389 } 389 390 if (!$this->start_transaction) { 390 $query = 'SET AUTOCOMMIT = 0';391 $query = 'SET AUTOCOMMIT = 1'; 391 392 $result =& $this->_doQuery($query, true); 392 393 if (PEAR::isError($result)) { … … 419 420 'rollback cannot be done changes are auto committed', __FUNCTION__); 420 421 } 421 if ( !is_null($savepoint)) {422 if (null !== $savepoint) { 422 423 if (!$this->supports('savepoints')) { 423 424 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, … … 434 435 } 435 436 if (!$this->start_transaction) { 436 $query = 'SET AUTOCOMMIT = 0';437 $query = 'SET AUTOCOMMIT = 1'; 437 438 $result =& $this->_doQuery($query, true); 438 439 if (PEAR::isError($result)) { … … 591 592 function setCharset($charset, $connection = null) 592 593 { 593 if ( is_null($connection)) {594 if (null === $connection) { 594 595 $connection = $this->getConnection(); 595 596 if (PEAR::isError($connection)) { … … 607 608 ) { 608 609 $query = "SET NAMES '".mysqli_real_escape_string($connection, $charset)."'"; 609 if ( !is_null($collation)) {610 if (null !== $collation) { 610 611 $query .= " COLLATE '".mysqli_real_escape_string($connection, $collation)."'"; 611 612 } … … 674 675 675 676 if ($force) { 676 @mysqli_close($this->connection); 677 } 677 $ok = @mysqli_close($this->connection); 678 if (!$ok) { 679 return $this->raiseError(MDB2_ERROR_DISCONNECT_FAILED, 680 null, null, null, __FUNCTION__); 681 } 682 } 683 } else { 684 return false; 678 685 } 679 686 return parent::disconnect($force); … … 743 750 } 744 751 745 if ( is_null($connection)) {752 if (null === $connection) { 746 753 $connection = $this->getConnection(); 747 754 if (PEAR::isError($connection)) { … … 749 756 } 750 757 } 751 if ( is_null($database_name)) {758 if (null === $database_name) { 752 759 $database_name = $this->database_name; 753 760 } … … 771 778 } 772 779 773 if (!$result ) {780 if (!$result && 0 !== mysqli_errno($connection)) { 774 781 $err =& $this->raiseError(null, null, null, 775 782 'Could not execute statement', __FUNCTION__); … … 808 815 function _affectedRows($connection, $result = null) 809 816 { 810 if ( is_null($connection)) {817 if (null === $connection) { 811 818 $connection = $this->getConnection(); 812 819 if (PEAR::isError($connection)) { … … 947 954 } 948 955 949 // SAVEPOINT Swere introduced in MySQL 4.0.14 and 4.1.1 (InnoDB)956 // SAVEPOINTs were introduced in MySQL 4.0.14 and 4.1.1 (InnoDB) 950 957 if (version_compare($server_version, '4.1.0', '>=')) { 951 958 if (version_compare($server_version, '4.1.1', '<')) { … … 989 996 { 990 997 $found = strpos(strrev(substr($query, 0, $position)), '@'); 991 if ( $found === false) {998 if (false === $found) { 992 999 return $position; 993 1000 } … … 1026 1033 function &prepare($query, $types = null, $result_types = null, $lobs = array()) 1027 1034 { 1035 // connect to get server capabilities (http://pear.php.net/bugs/16147) 1036 $connection = $this->getConnection(); 1037 if (PEAR::isError($connection)) { 1038 return $connection; 1039 } 1040 1028 1041 if ($this->options['emulate_prepared'] 1029 1042 || $this->supported['prepared_statements'] !== true … … 1061 1074 break; 1062 1075 } 1063 if ( is_null($placeholder_type)) {1076 if (null === $placeholder_type) { 1064 1077 $placeholder_type_guess = $query[$p_position]; 1065 1078 } … … 1082 1095 1083 1096 if ($query[$position] == $placeholder_type_guess) { 1084 if ( is_null($placeholder_type)) {1097 if (null === $placeholder_type) { 1085 1098 $placeholder_type = $query[$p_position]; 1086 1099 $question = $colon = $placeholder_type; … … 1104 1117 } 1105 1118 } 1106 $connection = $this->getConnection();1107 if (PEAR::isError($connection)) {1108 return $connection;1109 }1110 1119 1111 1120 if (!$is_manip) { … … 1141 1150 * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 1142 1151 * query, except that if there is already a row in the table with the same 1143 * key field values, the REPLACE query just updates its values instead of 1144 * inserting a new row. 1152 * key field values, the old row is deleted before the new row is inserted. 1145 1153 * 1146 1154 * The REPLACE type of query does not make part of the SQL standards. Since … … 1200 1208 * Default: 0 1201 1209 * 1210 * @see http://dev.mysql.com/doc/refman/5.0/en/replace.html 1202 1211 * @return mixed MDB2_OK on success, a MDB2 error on failure 1203 1212 */ … … 1358 1367 function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 1359 1368 { 1360 if ( !is_null($rownum)) {1369 if (null !== $rownum) { 1361 1370 $seek = $this->seek($rownum); 1362 1371 if (PEAR::isError($seek)) { … … 1379 1388 1380 1389 if (!$row) { 1381 if ( $this->result === false) {1390 if (false === $this->result) { 1382 1391 $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1383 1392 'resultset has already been freed', __FUNCTION__); … … 1410 1419 $row = (object) $row; 1411 1420 } else { 1412 $row = new $object_class($row); 1421 $rowObj = new $object_class($row); 1422 $row = $rowObj; 1413 1423 } 1414 1424 } … … 1459 1469 { 1460 1470 $cols = @mysqli_num_fields($this->result); 1461 if ( is_null($cols)) {1462 if ( $this->result === false) {1471 if (null === $cols) { 1472 if (false === $this->result) { 1463 1473 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1464 1474 'resultset has already been freed', __FUNCTION__); 1465 } elseif (is_null($this->result)) { 1475 } 1476 if (null === $this->result) { 1466 1477 return count($this->types); 1467 1478 } … … 1511 1522 function free() 1512 1523 { 1513 if (is_object($this->result) && $this->db->connection) { 1514 $free = @mysqli_free_result($this->result); 1515 if ($free === false) { 1516 return $this->db->raiseError(null, null, null, 1517 'Could not free result', __FUNCTION__); 1518 } 1519 } 1524 do { 1525 if (is_object($this->result) && $this->db->connection) { 1526 $free = @mysqli_free_result($this->result); 1527 if (false === $free) { 1528 return $this->db->raiseError(null, null, null, 1529 'Could not free result', __FUNCTION__); 1530 } 1531 } 1532 } while ($this->result = $this->nextResult()); 1533 1520 1534 $this->result = false; 1521 1535 return MDB2_OK; … … 1545 1559 { 1546 1560 if ($this->rownum != ($rownum - 1) && !@mysqli_data_seek($this->result, $rownum)) { 1547 if ( $this->result === false) {1561 if (false === $this->result) { 1548 1562 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1549 1563 'resultset has already been freed', __FUNCTION__); 1550 } elseif (is_null($this->result)) { 1564 } 1565 if (null === $this->result) { 1551 1566 return MDB2_OK; 1552 1567 } … … 1588 1603 { 1589 1604 $rows = @mysqli_num_rows($this->result); 1590 if ( is_null($rows)) {1591 if ( $this->result === false) {1605 if (null === $rows) { 1606 if (false === $this->result) { 1592 1607 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1593 1608 'resultset has already been freed', __FUNCTION__); 1594 } elseif (is_null($this->result)) { 1609 } 1610 if (null === $this->result) { 1595 1611 return 0; 1596 1612 } … … 1647 1663 * @param mixed $result_class string which specifies which result class to use 1648 1664 * @param mixed $result_wrap_class string which specifies which class to wrap results in 1649 * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure 1665 * 1666 * @return mixed MDB2_Result or integer (affected rows) on success, 1667 * a MDB2 error on failure 1650 1668 * @access private 1651 1669 */ 1652 1670 function &_execute($result_class = true, $result_wrap_class = false) 1653 1671 { 1654 if ( is_null($this->statement)) {1672 if (null === $this->statement) { 1655 1673 $result =& parent::_execute($result_class, $result_wrap_class); 1656 1674 return $result; … … 1732 1750 } else { 1733 1751 $result = @call_user_func_array('mysqli_stmt_bind_param', $parameters); 1734 if ( $result === false) {1752 if (false === $result) { 1735 1753 $err =& $this->db->raiseError(null, null, null, 1736 1754 'Unable to bind parameters', __FUNCTION__); … … 1814 1832 function free() 1815 1833 { 1816 if ( is_null($this->positions)) {1834 if (null === $this->positions) { 1817 1835 return $this->db->raiseError(MDB2_ERROR, null, null, 1818 1836 'Prepared statement has already been freed', __FUNCTION__); … … 1825 1843 'Could not free statement', __FUNCTION__); 1826 1844 } 1827 } elseif ( !is_null($this->statement)) {1845 } elseif (null !== $this->statement) { 1828 1846 $connection = $this->db->getConnection(); 1829 1847 if (PEAR::isError($connection)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/pgsql.php
r3039 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: pgsql.php ,v 1.197 2008/03/08 14:18:39 quipo Exp$46 // $Id: pgsql.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 48 48 /** … … 96 96 $this->options['DBA_password'] = false; 97 97 $this->options['multi_query'] = false; 98 $this->options['disable_smart_seqname'] = false;98 $this->options['disable_smart_seqname'] = true; 99 99 $this->options['max_identifiers_length'] = 63; 100 100 } … … 136 136 => MDB2_ERROR_NOSUCHTABLE, 137 137 '/database .* does not exist/' 138 => MDB2_ERROR_NOT_FOUND, 139 '/constraint .* does not exist/' 138 140 => MDB2_ERROR_NOT_FOUND, 139 141 '/index .* does not exist/' … … 235 237 { 236 238 $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 237 if ( !is_null($savepoint)) {239 if (null !== $savepoint) { 238 240 if (!$this->in_transaction) { 239 241 return $this->raiseError(MDB2_ERROR_INVALID, null, null, … … 242 244 $query = 'SAVEPOINT '.$savepoint; 243 245 return $this->_doQuery($query, true); 244 } elseif ($this->in_transaction) { 246 } 247 if ($this->in_transaction) { 245 248 return MDB2_OK; //nothing to do 246 249 } … … 278 281 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 279 282 } 280 if ( !is_null($savepoint)) {283 if (null !== $savepoint) { 281 284 $query = 'RELEASE SAVEPOINT '.$savepoint; 282 285 return $this->_doQuery($query, true); … … 312 315 'rollback cannot be done changes are auto committed', __FUNCTION__); 313 316 } 314 if ( !is_null($savepoint)) {317 if (null !== $savepoint) { 315 318 $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; 316 319 return $this->_doQuery($query, true); … … 424 427 } 425 428 426 if (!empty($this->dsn['new_link']) 427 && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)) 428 { 429 if ($this->_isNewLinkSet()) { 429 430 if (version_compare(phpversion(), '4.3.0', '>=')) { 430 431 $params[] = PGSQL_CONNECT_FORCE_NEW; … … 450 451 if (PEAR::isError($result)) { 451 452 return $result; 453 } 454 } 455 456 // Enable extra compatibility settings on 8.2 and later 457 if (function_exists('pg_parameter_status')) { 458 $version = pg_parameter_status($connection, 'server_version'); 459 if ($version == false) { 460 return $this->raiseError(null, null, null, 461 'Unable to retrieve server version', __FUNCTION__); 462 } 463 $version = explode ('.', $version); 464 if ( $version['0'] > 8 465 || ($version['0'] == 8 && $version['1'] >= 2) 466 ) { 467 if (!@pg_query($connection, "SET SESSION STANDARD_CONFORMING_STRINGS = OFF")) { 468 return $this->raiseError(null, null, null, 469 'Unable to set standard_conforming_strings to off', __FUNCTION__); 470 } 471 472 if (!@pg_query($connection, "SET SESSION ESCAPE_STRING_WARNING = OFF")) { 473 return $this->raiseError(null, null, null, 474 'Unable to set escape_string_warning to off', __FUNCTION__); 475 } 452 476 } 453 477 } … … 510 534 function setCharset($charset, $connection = null) 511 535 { 512 if ( is_null($connection)) {536 if (null === $connection) { 513 537 $connection = $this->getConnection(); 514 538 if (PEAR::isError($connection)) { … … 581 605 582 606 if (!$this->opened_persistent || $force) { 583 @pg_close($this->connection); 584 } 607 $ok = @pg_close($this->connection); 608 if (!$ok) { 609 return $this->raiseError(MDB2_ERROR_DISCONNECT_FAILED, 610 null, null, null, __FUNCTION__); 611 } 612 } 613 } else { 614 return false; 585 615 } 586 616 return parent::disconnect($force); … … 654 684 } 655 685 656 if ( is_null($connection)) {686 if (null === $connection) { 657 687 $connection = $this->getConnection(); 658 688 if (PEAR::isError($connection)) { … … 692 722 function _affectedRows($connection, $result = null) 693 723 { 694 if ( is_null($connection)) {724 if (null === $connection) { 695 725 $connection = $this->getConnection(); 696 726 if (PEAR::isError($connection)) { … … 880 910 break; 881 911 } 882 if ( is_null($placeholder_type)) {912 if (null === $placeholder_type) { 883 913 $placeholder_type_guess = $query[$p_position]; 884 914 } … … 894 924 895 925 if ($query[$position] == $placeholder_type_guess) { 896 if ( is_null($placeholder_type)) {926 if (null === $placeholder_type) { 897 927 $placeholder_type = $query[$p_position]; 898 928 $question = $colon = $placeholder_type; … … 953 983 $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand())); 954 984 $statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']); 955 if ( $pgtypes === false) {985 if (false === $pgtypes) { 956 986 $result = @pg_prepare($connection, $statement_name, $query); 957 987 if (!$result) { … … 1037 1067 } 1038 1068 1039 return sprintf($this->options['seqname_format'], 1040 preg_replace('/[^\w\$.]/i', '_', $sqn)); 1069 return parent::getSequenceName($sqn); 1041 1070 } 1042 1071 … … 1138 1167 function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 1139 1168 { 1140 if ( !is_null($rownum)) {1169 if (null !== $rownum) { 1141 1170 $seek = $this->seek($rownum); 1142 1171 if (PEAR::isError($seek)) { … … 1158 1187 } 1159 1188 if (!$row) { 1160 if ( $this->result === false) {1189 if (false === $this->result) { 1161 1190 $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1162 1191 'resultset has already been freed', __FUNCTION__); … … 1189 1218 $row = (object) $row; 1190 1219 } else { 1191 $row = new $object_class($row); 1220 $rowObj = new $object_class($row); 1221 $row = $rowObj; 1192 1222 } 1193 1223 } … … 1238 1268 { 1239 1269 $cols = @pg_num_fields($this->result); 1240 if ( is_null($cols)) {1241 if ( $this->result === false) {1270 if (null === $cols) { 1271 if (false === $this->result) { 1242 1272 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1243 1273 'resultset has already been freed', __FUNCTION__); 1244 } elseif (is_null($this->result)) { 1274 } 1275 if (null === $this->result) { 1245 1276 return count($this->types); 1246 1277 } … … 1286 1317 if (is_resource($this->result) && $this->db->connection) { 1287 1318 $free = @pg_free_result($this->result); 1288 if ( $free === false) {1319 if (false === $free) { 1289 1320 return $this->db->raiseError(null, null, null, 1290 1321 'Could not free result', __FUNCTION__); … … 1317 1348 { 1318 1349 if ($this->rownum != ($rownum - 1) && !@pg_result_seek($this->result, $rownum)) { 1319 if ( $this->result === false) {1350 if (false === $this->result) { 1320 1351 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1321 1352 'resultset has already been freed', __FUNCTION__); 1322 } elseif (is_null($this->result)) { 1353 } 1354 if (null === $this->result) { 1323 1355 return MDB2_OK; 1324 1356 } … … 1360 1392 { 1361 1393 $rows = @pg_num_rows($this->result); 1362 if ( is_null($rows)) {1363 if ( $this->result === false) {1394 if (null === $rows) { 1395 if (false === $this->result) { 1364 1396 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1365 1397 'resultset has already been freed', __FUNCTION__); 1366 } elseif (is_null($this->result)) { 1398 } 1399 if (null === $this->result) { 1367 1400 return 0; 1368 1401 } … … 1390 1423 * @param mixed $result_class string which specifies which result class to use 1391 1424 * @param mixed $result_wrap_class string which specifies which class to wrap results in 1392 * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure 1425 * 1426 * @return mixed MDB2_Result or integer (affected rows) on success, 1427 * a MDB2 error on failure 1393 1428 * @access private 1394 1429 */ 1395 1430 function &_execute($result_class = true, $result_wrap_class = false) 1396 1431 { 1397 if ( is_null($this->statement)) {1432 if (null === $this->statement) { 1398 1433 $result =& parent::_execute($result_class, $result_wrap_class); 1399 1434 return $result; … … 1491 1526 function free() 1492 1527 { 1493 if ( is_null($this->positions)) {1528 if (null === $this->positions) { 1494 1529 return $this->db->raiseError(MDB2_ERROR, null, null, 1495 1530 'Prepared statement has already been freed', __FUNCTION__); … … 1497 1532 $result = MDB2_OK; 1498 1533 1499 if ( !is_null($this->statement)) {1534 if (null !== $this->statement) { 1500 1535 $connection = $this->db->getConnection(); 1501 1536 if (PEAR::isError($connection)) { -
trunk/roundcubemail/program/lib/MDB2/Driver/sqlite.php
r3039 r3227 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: sqlite.php ,v 1.158 2008/03/08 14:18:39 quipo Exp$46 // $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $ 47 47 // 48 48 … … 132 132 $native_msg = preg_replace('/^sqlite[a-z_]+\(\)[^:]*: /', '', $native_msg); 133 133 134 if ( is_null($error)) {134 if (null === $error) { 135 135 static $error_regexps; 136 136 if (empty($error_regexps)) { … … 195 195 { 196 196 $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 197 if ( !is_null($savepoint)) {197 if (null !== $savepoint) { 198 198 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 199 199 'savepoints are not supported', __FUNCTION__); 200 } elseif ($this->in_transaction) { 200 } 201 if ($this->in_transaction) { 201 202 return MDB2_OK; //nothing to do 202 203 } … … 235 236 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 236 237 } 237 if ( !is_null($savepoint)) {238 if (null !== $savepoint) { 238 239 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 239 240 'savepoints are not supported', __FUNCTION__); … … 270 271 'rollback cannot be done changes are auto committed', __FUNCTION__); 271 272 } 272 if ( !is_null($savepoint)) {273 if (null !== $savepoint) { 273 274 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 274 275 'savepoints are not supported', __FUNCTION__); … … 365 366 } 366 367 367 if (!empty($this->database_name)) { 368 if ($database_file !== ':memory:') { 368 if (empty($this->database_name)) { 369 return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 370 'unable to establish a connection', __FUNCTION__); 371 } 372 373 if ($database_file !== ':memory:') { 374 if (!file_exists($database_file)) { 375 if (!touch($database_file)) { 376 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 377 'Could not create database file', __FUNCTION__); 378 } 379 if (!isset($this->dsn['mode']) 380 || !is_numeric($this->dsn['mode']) 381 ) { 382 $mode = 0644; 383 } else { 384 $mode = octdec($this->dsn['mode']); 385 } 386 if (!chmod($database_file, $mode)) { 387 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 388 'Could not be chmodded database file', __FUNCTION__); 389 } 369 390 if (!file_exists($database_file)) { 370 if (!touch($database_file)) { 371 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 372 'Could not create database file', __FUNCTION__); 373 } 374 if (!isset($this->dsn['mode']) 375 || !is_numeric($this->dsn['mode']) 376 ) { 377 $mode = 0644; 378 } else { 379 $mode = octdec($this->dsn['mode']); 380 } 381 if (!chmod($database_file, $mode)) { 382 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 383 'Could not be chmodded database file', __FUNCTION__); 384 } 385 if (!file_exists($database_file)) { 386 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 387 'Could not be found database file', __FUNCTION__); 388 } 391 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 392 'Could not be found database file', __FUNCTION__); 389 393 } 390 if (!is_file($database_file)) { 391 return $this->raiseError(MDB2_ERROR_INVALID, null, null, 392 'Database is a directory name', __FUNCTION__); 393 } 394 if (!is_readable($database_file)) { 395 return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, 396 'Could not read database file', __FUNCTION__); 397 } 398 } 399 400 $connect_function = ($this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'); 401 $php_errormsg = ''; 402 if (version_compare('5.1.0', PHP_VERSION, '>')) { 403 @ini_set('track_errors', true); 404 $connection = @$connect_function($database_file); 405 @ini_restore('track_errors'); 406 } else { 407 $connection = @$connect_function($database_file, 0666, $php_errormsg); 408 } 409 $this->_lasterror = $php_errormsg; 410 if (!$connection) { 411 return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 412 'unable to establish a connection', __FUNCTION__); 413 } 414 415 /* 416 if (!empty($this->dsn['charset'])) { 417 $result = $this->setCharset($this->dsn['charset'], $connection); 418 if (PEAR::isError($result)) { 419 return $result; 420 } 421 } 422 */ 423 424 $this->connection = $connection; 425 $this->connected_dsn = $this->dsn; 426 $this->connected_database_name = $database_file; 427 $this->opened_persistent = $this->getoption('persistent'); 428 $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; 429 } 394 } 395 if (!is_file($database_file)) { 396 return $this->raiseError(MDB2_ERROR_INVALID, null, null, 397 'Database is a directory name', __FUNCTION__); 398 } 399 if (!is_readable($database_file)) { 400 return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, 401 'Could not read database file', __FUNCTION__); 402 } 403 } 404 405 $connect_function = ($this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'); 406 $php_errormsg = ''; 407 if (version_compare('5.1.0', PHP_VERSION, '>')) { 408 @ini_set('track_errors', true); 409 $connection = @$connect_function($database_file); 410 @ini_restore('track_errors'); 411 } else { 412 $connection = @$connect_function($database_file, 0666, $php_errormsg); 413 } 414 $this->_lasterror = $php_errormsg; 415 if (!$connection) { 416 return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 417 'unable to establish a connection', __FUNCTION__); 418 } 419 420 if ($this->fix_assoc_fields_names || 421 $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES) 422 { 423 @sqlite_query("PRAGMA short_column_names = 1", $connection); 424 $this->fix_assoc_fields_names = true; 425 } 426 427 $this->connection = $connection; 428 $this->connected_dsn = $this->dsn; 429 $this->connected_database_name = $database_file; 430 $this->opened_persistent = $this->getoption('persistent'); 431 $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; 432 430 433 return MDB2_OK; 431 434 } … … 480 483 @sqlite_close($this->connection); 481 484 } 485 } else { 486 return false; 482 487 } 483 488 return parent::disconnect($force); 484 }485 486 // }}}487 // {{{ getConnection()488 489 /**490 * Returns a native connection491 *492 * @return mixed a valid MDB2 connection object,493 * or a MDB2 error object on error494 * @access public495 */496 function getConnection()497 {498 $connection = parent::getConnection();499 if (PEAR::isError($connection)) {500 return $connection;501 }502 503 $fix_assoc_fields_names = $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES;504 if ($fix_assoc_fields_names !== $this->fix_assoc_fields_names) {505 @sqlite_query("PRAGMA short_column_names = $fix_assoc_fields_names;", $connection);506 $this->fix_assoc_fields_names = $fix_assoc_fields_names;507 }508 509 return $connection;510 489 } 511 490 … … 537 516 } 538 517 539 if ( is_null($connection)) {518 if (null === $connection) { 540 519 $connection = $this->getConnection(); 541 520 if (PEAR::isError($connection)) { … … 583 562 function _affectedRows($connection, $result = null) 584 563 { 585 if ( is_null($connection)) {564 if (null === $connection) { 586 565 $connection = $this->getConnection(); 587 566 if (PEAR::isError($connection)) { … … 674 653 * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 675 654 * query, except that if there is already a row in the table with the same 676 * key field values, the REPLACE query just updates its values instead of 677 * inserting a new row. 655 * key field values, the old row is deleted before the new row is inserted. 678 656 * 679 657 * The REPLACE type of query does not make part of the SQL standards. Since … … 899 877 function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 900 878 { 901 if ( !is_null($rownum)) {879 if (null !== $rownum) { 902 880 $seek = $this->seek($rownum); 903 881 if (PEAR::isError($seek)) { … … 919 897 } 920 898 if (!$row) { 921 if ( $this->result === false) {899 if (false === $this->result) { 922 900 $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 923 901 'resultset has already been freed', __FUNCTION__); … … 950 928 $row = (object) $row; 951 929 } else { 952 $row = new $object_class($row); 930 $rowObj = new $object_class($row); 931 $row = $rowObj; 953 932 } 954 933 } … … 999 978 { 1000 979 $cols = @sqlite_num_fields($this->result); 1001 if ( is_null($cols)) {1002 if ( $this->result === false) {980 if (null === $cols) { 981 if (false === $this->result) { 1003 982 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1004 983 'resultset has already been freed', __FUNCTION__); 1005 } elseif (is_null($this->result)) { 984 } 985 if (null === $this->result) { 1006 986 return count($this->types); 1007 987 } … … 1034 1014 { 1035 1015 if (!@sqlite_seek($this->result, $rownum)) { 1036 if ( $this->result === false) {1016 if (false === $this->result) { 1037 1017 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1038 1018 'resultset has already been freed', __FUNCTION__); 1039 } elseif (is_null($this->result)) { 1019 } 1020 if (null === $this->result) { 1040 1021 return MDB2_OK; 1041 1022 } … … 1077 1058 { 1078 1059 $rows = @sqlite_num_rows($this->result); 1079 if ( is_null($rows)) {1080 if ( $this->result === false) {1060 if (null === $rows) { 1061 if (false === $this->result) { 1081 1062 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 1082 1063 'resultset has already been freed', __FUNCTION__); 1083 } elseif (is_null($this->result)) { 1064 } 1065 if (null === $this->result) { 1084 1066 return 0; 1085 1067 } … … 1102 1084 1103 1085 } 1104 1105 1086 ?> -
trunk/roundcubemail/program/lib/MDB2/Extended.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Extended.php ,v 1.60 2007/11/28 19:49:34 quipo Exp$45 // $Id: Extended.php 292715 2009-12-28 14:06:34Z quipo $ 46 46 47 47 /** … … 215 215 } 216 216 217 if ( $where !== false && !is_null($where)) {217 if ((false !== $where) && (null !== $where)) { 218 218 if (is_array($where)) { 219 219 $where = implode(' AND ', $where); -
trunk/roundcubemail/program/lib/MDB2/Iterator.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: Iterator.php ,v 1.22 2006/05/06 14:03:41 lsmith Exp$45 // $Id: Iterator.php 212543 2006-05-06 14:03:41Z lsmith $ 46 46 47 47 /** -
trunk/roundcubemail/program/lib/MDB2/LOB.php
r1002 r3227 43 43 // +----------------------------------------------------------------------+ 44 44 // 45 // $Id: LOB.php ,v 1.34 2006/10/25 11:52:21 lsmith Exp$45 // $Id: LOB.php 222350 2006-10-25 11:52:21Z lsmith $ 46 46 47 47 /**
Note: See TracChangeset
for help on using the changeset viewer.
