Changeset 3227 in subversion


Ignore:
Timestamp:
Jan 26, 2010 8:45:16 AM (3 years ago)
Author:
alec
Message:
  • Add support for MDB2's 'sqlsrv' driver (#1486395)
Location:
trunk/roundcubemail
Files:
6 added
44 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r3226 r3227  
    22=========================== 
    33 
     4- Add support for MDB2's 'sqlsrv' driver (#1486395) 
    45- Use jQuery-1.4 
    56- Removed problematic browser-caching of messages 
  • trunk/roundcubemail/config/db.inc.php.dist

    r2947 r3227  
    1818// format is db_provider://user:password@host/database  
    1919// 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 
    2121 
    2222$rcmail_config['db_dsnw'] = 'mysql://roundcube:pass@localhost/roundcubemail'; 
  • trunk/roundcubemail/program/include/rcmail.php

    r3212 r3227  
    10521052 
    10531053    $cookie = session_get_cookie_params(); 
     1054 
    10541055    setcookie($name, $value, $exp, $cookie['path'], $cookie['domain'], 
    10551056      rcube_https_check(), true); 
  • trunk/roundcubemail/program/include/rcube_mdb2.php

    r3212 r3227  
    107107        $this->_sqlite_create_database($dbh, $this->sqlite_initials); 
    108108      } 
    109     else if ($this->db_provider!='mssql') 
     109    else if ($this->db_provider!='mssql' && $this->db_provider!='sqlsrv') 
    110110      $dbh->setCharset('utf8'); 
    111111 
     
    468468      { 
    469469      case 'mssql': 
     470      case 'sqlsrv': 
    470471        return "getdate()"; 
    471472 
     
    512513 
    513514      case 'mssql': 
     515      case 'sqlsrv': 
    514516        return "DATEDIFF(second, '19700101', $field) + DATEDIFF(second, GETDATE(), GETUTCDATE())"; 
    515517 
  • trunk/roundcubemail/program/lib/MDB2.php

    r3039 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    102102define('MDB2_ERROR_INSUFFICIENT_DATA',  -35); 
    103103define('MDB2_ERROR_NO_PERMISSION',      -36); 
     104define('MDB2_ERROR_DISCONNECT_FAILED',  -37); 
    104105 
    105106// }}} 
     
    343344                return $err; 
    344345            } 
     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            } 
    345351        } 
    346352        return MDB2_OK; 
     
    404410 
    405411    /** 
    406      * Create a new MDB2 connection object and connect to the specified 
     412     * Create a new MDB2_Driver_* connection object and connect to the specified 
    407413     * database 
    408414     * 
     
    418424     *          ^^ 
    419425     * 
    420      * @param   mixed   'data source name', see the MDB2::parseDSN 
    421      *                            method for a description of the dsn format. 
    422      *                            Can also be specified as an array of the 
    423      *                            format returned by MDB2::parseDSN. 
    424      * @param   array  An associative array of option names and 
    425      *                            their values. 
    426      * 
    427      * @return  mixed  a newly created MDB2 connection object, or a MDB2 
    428      *                  error object on error 
     426     * @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 
    429435     * 
    430436     * @access  public 
     
    567573    function apiVersion() 
    568574    { 
    569         return '2.5.0b1'; 
     575        return '@package_version@'; 
    570576    } 
    571577 
     
    628634    { 
    629635        if (is_a($data, 'MDB2_Error')) { 
    630             if (is_null($code)) { 
     636            if (null === $code) { 
    631637                return true; 
    632638            } elseif (is_string($code)) { 
     
    768774                MDB2_ERROR_DEADLOCK           => 'deadlock detected', 
    769775                MDB2_ERROR_NO_PERMISSION      => 'no permission', 
     776                MDB2_ERROR_DISCONNECT_FAILED  => 'disconnect failed', 
    770777            ); 
    771778        } 
    772779 
    773         if (is_null($value)) { 
     780        if (null === $value) { 
    774781            return $errorMessages; 
    775782        } 
     
    825832    function parseDSN($dsn) 
    826833    { 
    827         $parsed = array(); 
     834        $parsed = $GLOBALS['_MDB2_dsninfo_default']; 
    828835 
    829836        if (is_array($dsn)) { 
     
    844851        } 
    845852 
    846    
    847853        // Get phptype and dbsyntax 
    848854        // $str => phptype(dbsyntax) 
     
    856862 
    857863        if (!count($dsn)) { 
    858             return array_merge($GLOBALS['_MDB2_dsninfo_default'], $parsed); 
     864            return $parsed; 
    859865        } 
    860866 
     
    893899                //e.g. "scott/tiger@//mymachine:1521/oracle" 
    894900                $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); 
    896904            } elseif (strpos($dsn, '/') !== false) { 
    897905                list($proto_opts, $dsn) = explode('/', $dsn, 2); 
     
    931939                foreach ($opts as $opt) { 
    932940                    list($key, $value) = explode('=', $opt); 
    933                     if (!isset($parsed[$key])) { 
     941                    if (!array_key_exists($key, $parsed) || false === $parsed[$key]) { 
    934942                        // don't allow params overwrite 
    935943                        $parsed[$key] = rawurldecode($value); 
     
    939947        } 
    940948 
    941         return array_merge($GLOBALS['_MDB2_dsninfo_default'], $parsed); 
     949        return $parsed; 
    942950    } 
    943951 
     
    10021010              $level = E_USER_NOTICE, $debuginfo = null, $dummy = null) 
    10031011    { 
    1004         if (is_null($code)) { 
     1012        if (null === $code) { 
    10051013            $code = MDB2_ERROR; 
    10061014        } 
     
    11471155     *  <li>$options['datatype_map'] -> array: map user defined datatypes to other primitive datatypes</li> 
    11481156     *  <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> 
    11501159     *  <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> 
    11511162     * </ul> 
    11521163     * 
     
    11981209        'bindname_format' => '(?:\d+)|(?:[a-zA-Z][a-zA-Z0-9_]*)', 
    11991210        'max_identifiers_length' => 30, 
     1211        'default_fk_action_onupdate' => 'RESTRICT', 
     1212        'default_fk_action_ondelete' => 'RESTRICT', 
    12001213    ); 
    12011214 
     
    14281441     * without the message string. 
    14291442     * 
    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    ) { 
    14501471        $userinfo = "[Error message: $userinfo]\n"; 
    14511472        // The error is yet a MDB2 error object 
     
    14531474            // because we use the static PEAR::raiseError, our global 
    14541475            // 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)) { 
    14561477                $mode    = $this->_default_error_mode; 
    14571478                $options = $this->_default_error_options; 
    14581479            } 
    1459             if (is_null($userinfo)) { 
     1480            if (null === $userinfo) { 
    14601481                $userinfo = $code->getUserinfo(); 
    14611482            } 
     
    14701491            $native_errno = $native_msg = null; 
    14711492            list($code, $native_errno, $native_msg) = $this->errorInfo($code); 
    1472             if (!is_null($native_errno) && $native_errno !== '') { 
     1493            if ((null !== $native_errno) && $native_errno !== '') { 
    14731494                $userinfo.= "[Native code: $native_errno]\n"; 
    14741495            } 
    1475             if (!is_null($native_msg) && $native_msg !== '') { 
     1496            if ((null !== $native_msg) && $native_msg !== '') { 
    14761497                $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n"; 
    14771498            } 
    1478             if (!is_null($method)) { 
     1499            if (null !== $method) { 
    14791500                $userinfo = $method.': '.$userinfo; 
    14801501            } 
     
    19271948            } 
    19281949            $this->{$property} = new $class_name($this->db_index); 
    1929             $this->modules[$module] = $this->{$property}; 
     1950            $this->modules[$module] =& $this->{$property}; 
    19301951            if ($version) { 
    19311952                // this will be used in the connect method to determine if the module 
     
    19741995            } 
    19751996        } 
    1976         if (!is_null($module)) { 
     1997        if (null !== $module) { 
    19771998            return call_user_func_array(array(&$this->modules[$module], $method), $params); 
    19781999        } 
     
    21842205    function failNestedTransaction($error = null, $immediately = false) 
    21852206    { 
    2186         if (is_null($error)) { 
     2207        if (null !== $error) { 
    21872208            $error = $this->has_transaction_error ? $this->has_transaction_error : true; 
    21882209        } elseif (!$error) { 
     
    22662287     * Log out and disconnect from the database. 
    22672288     * 
    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 
    22732293     * 
    22742294     * @access  public 
     
    23862406 
    23872407    // }}} 
     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    // }}} 
    23882428    // {{{ function &standaloneQuery($query, $types = null, $is_manip = false) 
    23892429 
     
    25642604 
    25652605    // }}} 
    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) 
    25672607 
    25682608    /** 
     
    26352675                return $err; 
    26362676            } 
    2637             $result = new $result_wrap_class($result, $this->fetchmode); 
     2677            $result = new $result_wrap_class($result_resource, $this->fetchmode); 
    26382678        } 
    26392679        return $result; 
     
    26832723        } 
    26842724        $this->limit = $limit; 
    2685         if (!is_null($offset)) { 
     2725        if (null !== $offset) { 
    26862726            $offset = (int)$offset; 
    26872727            if ($offset < 0) { 
     
    27402780     * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 
    27412781     * 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. 
    27442783     * 
    27452784     * The REPLACE type of query does not make part of the SQL standards. Since 
     
    29132952        } 
    29142953        $placeholder_type_guess = $placeholder_type = null; 
    2915         $question = '?'; 
    2916         $colon = ':'; 
     2954        $question  = '?'; 
     2955        $colon     = ':'; 
    29172956        $positions = array(); 
    2918         $position = 0; 
    2919          
     2957        $position  = 0; 
    29202958        while ($position < strlen($query)) { 
    29212959            $q_position = strpos($query, $question, $position); 
     
    29302968                break; 
    29312969            } 
    2932             if (is_null($placeholder_type)) { 
     2970            if (null === $placeholder_type) { 
    29332971                $placeholder_type_guess = $query[$p_position]; 
    29342972            } 
     
    29442982 
    29452983            if ($query[$position] == $placeholder_type_guess) { 
    2946                 if (is_null($placeholder_type)) { 
     2984                if (null === $placeholder_type) { 
    29472985                    $placeholder_type = $query[$p_position]; 
    29482986                    $question = $colon = $placeholder_type; 
     
    30083046    function _skipDelimitedStrings($query, $position, $p_position) 
    30093047    { 
    3010         $ignores[] = $this->string_quoting; 
    3011         $ignores[] = $this->identifier_quoting; 
    3012          
     3048        $ignores = $this->string_quoting; 
     3049        $ignores[] = $this->identifier_quoting; 
    30133050        $ignores = array_merge($ignores, $this->sql_comments); 
    30143051         
     
    30283065                        } 
    30293066                    } 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 
    30343073                    $position = $end_quote + 1; 
    30353074                    return $position; 
     
    31713210    { 
    31723211        return sprintf($this->options['idxname_format'], 
    3173             preg_replace('/[^a-z0-9_\$]/i', '_', $idx)); 
     3212            preg_replace('/[^a-z0-9_\-\$.]/i', '_', $idx)); 
    31743213    } 
    31753214 
     
    32403279     * the result set. 
    32413280     * 
    3242      * @param   string  the SELECT query statement to be executed. 
    3243      * @param   string  optional argument that specifies the expected 
    3244      *       datatype of the result set field, so that an eventual conversion 
    3245      *       may be performed. The default datatype is text, meaning that no 
    3246      *       conversion is performed 
    3247      * @param   int     the column number to fetch 
     3281     * @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 
    32483287     * 
    32493288     * @return  mixed   MDB2_OK or field value on success, a MDB2 error on failure 
     
    33013340     * each row of the result set into an array and then frees the result set. 
    33023341     * 
    3303      * @param   string  the SELECT query statement to be executed. 
    3304      * @param   string  optional argument that specifies the expected 
    3305      *       datatype of the result set field, so that an eventual conversion 
    3306      *       may be performed. The default datatype is text, meaning that no 
    3307      *       conversion is performed 
    3308      * @param   int     the row number to fetch 
     3342     * @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 
    33093348     * 
    33103349     * @return  mixed   MDB2_OK or data array on success, a MDB2 error on failure 
    3311      * 
    33123350     * @access  public 
    33133351     */ 
     
    35193557     * fetch single column from the next row from a result set 
    35203558     * 
    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 
    35263563     * @access  public 
    35273564     */ 
     
    35463583     * Fetch and return a column from the current row pointer position 
    35473584     * 
    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 
    35523588     * @access  public 
    35533589     */ 
     
    36103646 
    36113647        $shift_array = $rekey ? false : null; 
    3612         if (!is_null($shift_array)) { 
     3648        if (null !== $shift_array) { 
    36133649            if (is_object($row)) { 
    36143650                $colnum = count(get_object_vars($row)); 
     
    38163852        } 
    38173853        $this->values[$column] =& $value; 
    3818         if (!is_null($type)) { 
     3854        if (null !== $type) { 
    38193855            $this->types[$column] = $type; 
    38203856        } 
     
    39864022        } 
    39874023        $this->values[$parameter] = $value; 
    3988         if (!is_null($type)) { 
     4024        if (null !== $type) { 
    39894025            $this->types[$parameter] = $type; 
    39904026        } 
     
    40554091        } 
    40564092        $this->values[$parameter] =& $value; 
    4057         if (!is_null($type)) { 
     4093        if (null !== $type) { 
    40584094            $this->types[$parameter] = $type; 
    40594095        } 
     
    40964132     * Execute a prepared query statement. 
    40974133     * 
    4098      * @param   array  specifies all necessary information 
    4099      *       for bindParam() the array elements must use keys corresponding to 
    4100      *       the number of the position of the parameter. 
    4101      * @param   mixed  specifies which result class to use 
    4102      * @param   mixed  specifies which class to wrap results in 
    4103      * 
    4104      * @return  mixed   a result handle or MDB2_OK on success, a MDB2 error on failure 
    4105      * 
    4106      * @access  public 
     4134     * @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 
    41074143     */ 
    41084144    function &execute($values = null, $result_class = true, $result_wrap_class = false) 
    41094145    { 
    4110         if (is_null($this->positions)) { 
     4146        if (null === $this->positions) { 
    41114147            return $this->db->raiseError(MDB2_ERROR, null, null, 
    41124148                'Prepared statement has already been freed', __FUNCTION__); 
     
    41344170     * @param   mixed   specifies which class to wrap results in 
    41354171     * 
    4136      * @return  mixed   MDB2_Result or integer on success, a MDB2 error on failure 
    4137      * 
     4172     * @return mixed MDB2_Result or integer (affected rows) on success, 
     4173     *               a MDB2 error on failure 
    41384174     * @access  private 
    41394175     */ 
     
    41864222    function free() 
    41874223    { 
    4188         if (is_null($this->positions)) { 
     4224        if (null === $this->positions) { 
    41894225            return $this->db->raiseError(MDB2_ERROR, null, null, 
    41904226                'Prepared statement has already been freed', __FUNCTION__); 
  • trunk/roundcubemail/program/lib/MDB2/Date.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/Common.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747require_once 'MDB2/LOB.php'; 
     
    233233    function convertResult($value, $type, $rtrim = true) 
    234234    { 
    235         if (is_null($value)) { 
     235        if (null === $value) { 
    236236            return null; 
    237237        } 
     
    314314            reset($types); 
    315315            foreach (array_keys($sorted_types) as $k) { 
    316                 if (is_null($sorted_types[$k])) { 
     316                if (null === $sorted_types[$k]) { 
    317317                    $sorted_types[$k] = current($types); 
    318318                    next($types); 
     
    512512                } 
    513513            } 
    514             if (!is_null($field['default'])) { 
     514            if (null !== $field['default']) { 
    515515                $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']); 
    516516            } 
     
    11201120        } 
    11211121 
    1122         if (is_null($value) 
     1122        if ((null === $value) 
    11231123            || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) 
    11241124        ) { 
     
    11291129        } 
    11301130 
    1131         if (is_null($type)) { 
     1131        if (null === $type) { 
    11321132            switch (gettype($value)) { 
    11331133            case 'integer': 
     
    12891289    function _quoteLOB($value, $quote, $escape_wildcards) 
    12901290    { 
    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            } 
    12941300        } 
    12951301        return $this->_quoteText($value, $quote, $escape_wildcards); 
     
    15551561    function _retrieveLOB(&$lob) 
    15561562    { 
    1557         if (is_null($lob['value'])) { 
     1563        if (null === $lob['value']) { 
    15581564            $lob['value'] = $lob['resource']; 
    15591565        } 
     
    16881694 
    16891695        $match = ''; 
    1690         if (!is_null($operator)) { 
     1696        if (null !== $operator) { 
    16911697            $operator = strtoupper($operator); 
    16921698            switch ($operator) { 
    16931699            // case insensitive 
    16941700            case 'ILIKE': 
    1695                 if (is_null($field)) { 
     1701                if (null === $field) { 
    16961702                    return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
    16971703                        'case insensitive LIKE matching requires passing the field name', __FUNCTION__); 
     
    17001706                $match = $db->function->lower($field).' LIKE '; 
    17011707                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; 
    17021716            // case sensitive 
    17031717            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 '); 
    17051722                break; 
    17061723            default: 
     
    17141731                $match.= $value; 
    17151732            } else { 
    1716                 if ($operator === 'ILIKE') { 
    1717                     $value = strtolower($value); 
    1718                 } 
    17191733                $escaped = $db->escape($value); 
    17201734                if (PEAR::isError($escaped)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/mssql.php

    r1352 r3227  
    4545// +----------------------------------------------------------------------+ 
    4646// 
    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 $ 
    4848// 
    4949 
     
    7272    function _baseConvertResult($value, $type, $rtrim = true) 
    7373    { 
    74         if (is_null($value)) { 
     74        if (null === $value) { 
    7575            return null; 
    7676        } 
     
    229229                $field['default'] = 0; 
    230230            } 
    231             if (is_null($field['default'])) { 
     231            if (null === $field['default']) { 
    232232                $default = ' DEFAULT (null)'; 
    233233            } else { 
     
    337337        $value = '0x'.bin2hex($this->_readFile($value)); 
    338338        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; 
    339398    } 
    340399 
     
    377436            $length = 8; 
    378437            break; 
     438        case 'smalldatetime': 
    379439        case 'datetime': 
    380440            $type[0] = 'timestamp'; 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/mysql.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    353353 
    354354        $match = ''; 
    355         if (!is_null($operator)) { 
    356             $field = is_null($field) ? '' : $field.' '; 
     355        if (null !== $operator) { 
     356            $field = (null === $field) ? '' : $field.' '; 
    357357            $operator = strtoupper($operator); 
    358358            switch ($operator) { 
     
    361361                $match = $field.'LIKE '; 
    362362                break; 
     363            case 'NOT ILIKE': 
     364                $match = $field.'NOT LIKE '; 
     365                break; 
    363366            // case sensitive 
    364367            case 'LIKE': 
    365368                $match = $field.'LIKE BINARY '; 
     369                break; 
     370            case 'NOT LIKE': 
     371                $match = $field.'NOT LIKE BINARY '; 
    366372                break; 
    367373            default: 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/mysqli.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    353353 
    354354        $match = ''; 
    355         if (!is_null($operator)) { 
    356             $field = is_null($field) ? '' : $field.' '; 
     355        if (null !== $operator) { 
     356            $field = (null === $field) ? '' : $field.' '; 
    357357            $operator = strtoupper($operator); 
    358358            switch ($operator) { 
     
    361361                $match = $field.'LIKE '; 
    362362                break; 
     363            case 'NOT ILIKE': 
     364                $match = $field.'NOT LIKE '; 
     365                break; 
    363366            // case sensitive 
    364367            case 'LIKE': 
    365368                $match = $field.'LIKE BINARY '; 
     369                break; 
     370            case 'NOT LIKE': 
     371                $match = $field.'NOT LIKE BINARY '; 
    366372                break; 
    367373            default: 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/pgsql.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747require_once 'MDB2/Driver/Datatype/Common.php'; 
     
    6969    function _baseConvertResult($value, $type, $rtrim = true) 
    7070    { 
    71         if (is_null($value)) { 
     71        if (null === $value) { 
    7272            return null; 
    7373        } 
     
    125125        switch ($field['type']) { 
    126126        case 'text': 
    127             $length = !empty($field['length']) 
    128                 ? $field['length'] : $db->options['default_text_field_length']; 
     127            $length = !empty($field['length']) ? $field['length'] : false; 
    129128            $fixed = !empty($field['fixed']) ? $field['fixed'] : false; 
    130129            return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') 
     
    241240    function _quoteCLOB($value, $quote, $escape_wildcards) 
    242241    { 
     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        } 
    243252        return $this->_quoteText($value, $quote, $escape_wildcards); 
    244253    } 
     
    263272            return $value; 
    264273        } 
     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        } 
    265284        if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) { 
    266             $db =& $this->getDBInstance(); 
    267             if (PEAR::isError($db)) { 
    268                 return $db; 
    269             } 
    270285            $connection = $db->getConnection(); 
    271286            if (PEAR::isError($connection)) { 
     
    325340 
    326341        $match = ''; 
    327         if (!is_null($operator)) { 
    328             $field = is_null($field) ? '' : $field.' '; 
     342        if (null !== $operator) { 
     343            $field = (null === $field) ? '' : $field.' '; 
    329344            $operator = strtoupper($operator); 
    330345            switch ($operator) { 
     
    333348                $match = $field.'ILIKE '; 
    334349                break; 
     350            case 'NOT ILIKE': 
     351                $match = $field.'NOT ILIKE '; 
     352                break; 
    335353            // case sensitive 
    336354            case 'LIKE': 
    337355                $match = $field.'LIKE '; 
     356                break; 
     357            case 'NOT LIKE': 
     358                $match = $field.'NOT LIKE '; 
    338359                break; 
    339360            default: 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Datatype/sqlite.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    244244 
    245245        $match = ''; 
    246         if (!is_null($operator)) { 
    247             $field = is_null($field) ? '' : $field.' '; 
     246        if (null !== $operator) { 
     247            $field = (null === $field) ? '' : $field.' '; 
    248248            $operator = strtoupper($operator); 
    249249            switch ($operator) { 
     
    252252                $match = $field.'LIKE '; 
    253253                break; 
     254            case 'NOT ILIKE': 
     255                $match = $field.'NOT LIKE '; 
     256                break; 
    254257            // case sensitive 
    255258            case 'LIKE': 
    256259                $match = $field.'LIKE '; 
     260                break; 
     261            case 'NOT LIKE': 
     262                $match = $field.'NOT LIKE '; 
    257263                break; 
    258264            default: 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Function/Common.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    167167    function substring($value, $position = 1, $length = null) 
    168168    { 
    169         if (!is_null($length)) { 
     169        if (null !== $length) { 
    170170            return "SUBSTRING($value FROM $position FOR $length)"; 
    171171        } 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Function/mssql.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    135135    function substring($value, $position = 1, $length = null) 
    136136    { 
    137         if (!is_null($length)) { 
     137        if (null !== $length) { 
    138138            return "SUBSTRING($value, $position, $length)"; 
    139139        } 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Function/mysql.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Function/mysqli.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Function/pgsql.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747require_once 'MDB2/Driver/Function/Common.php'; 
     
    9494    function unixtimestamp($expression) 
    9595    { 
    96         return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', TIMESTAMP '. $expression.'))'; 
     96        return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', CAST ((' . $expression . ') AS TIMESTAMP)))'; 
    9797    } 
    9898 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Function/sqlite.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    117117    function substring($value, $position = 1, $length = null) 
    118118    { 
    119         if (!is_null($length)) { 
    120             return "substr($value,$position,$length)"; 
     119        if (null !== $length) { 
     120            return "substr($value, $position, $length)"; 
    121121        } 
    122         return "substr($value,$position,length($value))"; 
     122        return "substr($value, $position, length($value))"; 
    123123    } 
    124124 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Manager/Common.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    7070    /** 
    7171     * 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) 
    7276     * @access private 
    7377     */ 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Manager/mssql.php

    r1352 r3227  
    4545// +----------------------------------------------------------------------+ 
    4646// 
    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 $ 
    4848// 
    4949 
     
    716716        } 
    717717 
    718         $table = $db->quoteIdentifier($table, true); 
     718        $table = $db->quote($table, 'text'); 
    719719        $columns = $db->queryCol("SELECT c.name 
    720720                                    FROM syscolumns c 
    721721                               LEFT JOIN sysobjects o ON c.id = o.id 
    722                                    WHERE o.name = '$table'"); 
     722                                   WHERE o.name = $table"); 
    723723        if (PEAR::isError($columns)) { 
    724724            return $columns; 
     
    894894                   WHERE xtype = 'TR' 
    895895                     AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0"; 
    896         if (!is_null($table)) { 
     896        if (null !== $table) { 
    897897            $query .= " AND object_name(parent_obj) = $table"; 
    898898        } 
     
    995995            return $db; 
    996996        } 
    997         $table = $db->quoteIdentifier($table, true); 
     997        $table = $db->quote($table, 'text'); 
    998998 
    999999        $query = "SELECT c.constraint_name 
    10001000                    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS c 
    10011001                   WHERE c.constraint_catalog = DB_NAME() 
    1002                      AND c.table_name = '$table'"; 
     1002                     AND c.table_name = $table"; 
    10031003        $constraints = $db->queryCol($query); 
    10041004        if (PEAR::isError($constraints)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Manager/mysql.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    223223                } 
    224224            } 
    225             if (!is_null($autoincrement) && count($pk_fields) > 1) { 
     225            if ((null !== $autoincrement) && count($pk_fields) > 1) { 
    226226                $options['primary'] = $pk_fields; 
    227227            } else { 
     
    236236        } 
    237237 
    238         if (!is_null($autoincrement)) { 
     238        if (null !== $autoincrement) { 
    239239            // we have to remove the PK clause added by _getIntegerDeclaration() 
    240240            $query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query); 
     
    660660 
    661661        $query = 'SHOW TRIGGERS'; 
    662         if (!is_null($table)) { 
     662        if (null !== $table) { 
    663663            $table = $db->quote($table, 'text'); 
    664664            $query .= " LIKE $table"; 
     
    692692 
    693693        $query = "SHOW /*!50002 FULL*/ TABLES"; 
    694         if (!is_null($database)) { 
     694        if (null !== $database) { 
    695695            $query .= " FROM $database"; 
    696696        } 
     
    732732 
    733733        $query = 'SHOW FULL TABLES'; 
    734         if (!is_null($database)) { 
     734        if (null !== $database) { 
    735735            $query.= " FROM $database"; 
    736736        } 
     
    941941 
    942942        $type = ''; 
    943         $name = $db->quoteIdentifier($db->getIndexName($name), true); 
     943        $idx_name = $db->quoteIdentifier($db->getIndexName($name), true); 
    944944        if (!empty($definition['primary'])) { 
    945945            $type = 'PRIMARY'; 
    946             $name = 'KEY'; 
     946            $idx_name = 'KEY'; 
    947947        } elseif (!empty($definition['unique'])) { 
    948948            $type = 'UNIQUE'; 
     
    956956 
    957957        $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"; 
    959959        if (!empty($definition['foreign'])) { 
    960960            $query .= ' FOREIGN KEY'; 
    961961        } 
    962962        $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; 
    965969        } 
    966970        $query .= ' ('. implode(', ', $fields) . ')'; 
     
    973977            $query .= ' ('. implode(', ', $referenced_fields) . ')'; 
    974978            $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            } 
    975986        } 
    976987        $res = $db->exec($query); 
     
    10541065        // create triggers to enforce FOREIGN KEY constraints 
    10551066        if ($db->supports('triggers') && !empty($foreign_keys)) { 
    1056             $table = $db->quoteIdentifier($table, true); 
     1067            $table_quoted = $db->quoteIdentifier($table, true); 
    10571068            foreach ($foreign_keys as $fkname => $fkdef) { 
    10581069                if (empty($fkdef)) { 
    10591070                    continue; 
    10601071                } 
    1061                 //set actions to 'RESTRICT' if not set 
    1062                 $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']); 
    10641075 
    10651076                $trigger_names = array( 
     
    10761087                $aliased_fields = array(); 
    10771088                foreach ($table_fields as $field) { 
    1078                     $aliased_fields[] = $table .'.'.$field .' AS '.$field; 
     1089                    $aliased_fields[] = $table_quoted .'.'.$field .' AS '.$field; 
    10791090                } 
    10801091                $restrict_action .= implode(',', $aliased_fields) 
    1081                        .' FROM '.$table 
     1092                       .' FROM '.$table_quoted 
    10821093                       .' WHERE '; 
    10831094                $conditions  = array(); 
     
    10891100                    $null_values[] = $table_fields[$i] .' = NULL'; 
    10901101                } 
    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). ';'; 
    10981120 
    10991121                if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) { 
     
    11071129                        $default_values[] = $table_field .' = '. $field_definition[0]['default']; 
    11081130                    } 
    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). ';'; 
    11101132                } 
    11111133 
     
    11231145                } elseif ('NO ACTION' == $fkdef['onupdate']) { 
    11241146                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update'); 
    1125                 } else { 
    1126                     //'RESTRICT' 
     1147                } elseif ('RESTRICT' == $fkdef['onupdate']) { 
    11271148                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update'); 
    11281149                } 
     
    11351156                } elseif ('NO ACTION' == $fkdef['ondelete']) { 
    11361157                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete'); 
    1137                 } else { 
    1138                     //'RESTRICT' 
     1158                } elseif ('RESTRICT' == $fkdef['ondelete']) { 
    11391159                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete'); 
    11401160                } 
     
    13941414 
    13951415        $query = "SHOW TABLES"; 
    1396         if (!is_null($database)) { 
     1416        if (null !== $database) { 
    13971417            $query .= " FROM $database"; 
    13981418        } 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Manager/mysqli.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    223223                } 
    224224            } 
    225             if (!is_null($autoincrement) && count($pk_fields) > 1) { 
     225            if ((null !== $autoincrement) && count($pk_fields) > 1) { 
    226226                $options['primary'] = $pk_fields; 
    227227            } else { 
     
    236236        } 
    237237 
    238         if (!is_null($autoincrement)) { 
     238        if (null !== $autoincrement) { 
    239239            // we have to remove the PK clause added by _getIntegerDeclaration() 
    240240            $query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query); 
     
    660660 
    661661        $query = 'SHOW TRIGGERS'; 
    662         if (!is_null($table)) { 
     662        if (null !== $table) { 
    663663            $table = $db->quote($table, 'text'); 
    664664            $query .= " LIKE $table"; 
     
    692692 
    693693        $query = "SHOW /*!50002 FULL*/ TABLES"; 
    694         if (!is_null($database)) { 
     694        if (null !== $database) { 
    695695            $query .= " FROM $database"; 
    696696        } 
     
    732732 
    733733        $query = 'SHOW FULL TABLES'; 
    734         if (!is_null($database)) { 
     734        if (null !== $database) { 
    735735            $query.= " FROM $database"; 
    736736        } 
     
    941941 
    942942        $type = ''; 
    943         $name = $db->quoteIdentifier($db->getIndexName($name), true); 
     943        $idx_name = $db->quoteIdentifier($db->getIndexName($name), true); 
    944944        if (!empty($definition['primary'])) { 
    945945            $type = 'PRIMARY'; 
    946             $name = 'KEY'; 
     946            $idx_name = 'KEY'; 
    947947        } elseif (!empty($definition['unique'])) { 
    948948            $type = 'UNIQUE'; 
     
    956956 
    957957        $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"; 
    959959        if (!empty($definition['foreign'])) { 
    960960            $query .= ' FOREIGN KEY'; 
    961961        } 
    962962        $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; 
    965969        } 
    966970        $query .= ' ('. implode(', ', $fields) . ')'; 
     
    973977            $query .= ' ('. implode(', ', $referenced_fields) . ')'; 
    974978            $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            } 
    975986        } 
    976987        $res = $db->exec($query); 
     
    10541065        // create triggers to enforce FOREIGN KEY constraints 
    10551066        if ($db->supports('triggers') && !empty($foreign_keys)) { 
    1056             $table = $db->quoteIdentifier($table, true); 
     1067            $table_quoted = $db->quoteIdentifier($table, true); 
    10571068            foreach ($foreign_keys as $fkname => $fkdef) { 
    10581069                if (empty($fkdef)) { 
    10591070                    continue; 
    10601071                } 
    1061                 //set actions to 'RESTRICT' if not set 
    1062                 $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']); 
    10641075 
    10651076                $trigger_names = array( 
     
    10761087                $aliased_fields = array(); 
    10771088                foreach ($table_fields as $field) { 
    1078                     $aliased_fields[] = $table .'.'.$field .' AS '.$field; 
     1089                    $aliased_fields[] = $table_quoted .'.'.$field .' AS '.$field; 
    10791090                } 
    10801091                $restrict_action .= implode(',', $aliased_fields) 
    1081                        .' FROM '.$table 
     1092                       .' FROM '.$table_quoted 
    10821093                       .' WHERE '; 
    10831094                $conditions  = array(); 
     
    10891100                    $null_values[] = $table_fields[$i] .' = NULL'; 
    10901101                } 
    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). ';'; 
    10981120 
    10991121                if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) { 
     
    11071129                        $default_values[] = $table_field .' = '. $field_definition[0]['default']; 
    11081130                    } 
    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). ';'; 
    11101132                } 
    11111133 
     
    11231145                } elseif ('NO ACTION' == $fkdef['onupdate']) { 
    11241146                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update'); 
    1125                 } else { 
    1126                     //'RESTRICT' 
     1147                } elseif ('RESTRICT' == $fkdef['onupdate']) { 
    11271148                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update'); 
    11281149                } 
     
    11351156                } elseif ('NO ACTION' == $fkdef['ondelete']) { 
    11361157                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete'); 
    1137                 } else { 
    1138                     //'RESTRICT' 
     1158                } elseif ('RESTRICT' == $fkdef['ondelete']) { 
    11391159                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete'); 
    11401160                } 
     
    13941414 
    13951415        $query = "SHOW TABLES"; 
    1396         if (!is_null($database)) { 
     1416        if (null !== $database) { 
    13971417            $query .= " FROM $database"; 
    13981418        } 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Manager/pgsql.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747require_once 'MDB2/Driver/Manager/Common.php'; 
     
    350350        } 
    351351 
     352        $name = $db->quoteIdentifier($name, true); 
     353 
    352354        if (!empty($changes['remove']) && is_array($changes['remove'])) { 
    353355            foreach ($changes['remove'] as $field_name => $field) { 
     
    394396                    } 
    395397                    $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)"; 
    397400                    $result = $db->exec("ALTER TABLE $name $query"); 
    398401                    if (PEAR::isError($result)) { 
     
    407410                    } 
    408411                } 
    409                 if (!empty($field['definition']['notnull'])) { 
     412                if (array_key_exists('notnull', $field['definition'])) { 
    410413                    $query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL'; 
    411414                    $result = $db->exec("ALTER TABLE $name $query"); 
     
    417420        } 
    418421 
    419         $name = $db->quoteIdentifier($name, true); 
    420422        if (!empty($changes['name'])) { 
    421423            $change_name = $db->quoteIdentifier($changes['name'], true); 
     
    607609                         pg_class tbl 
    608610                   WHERE trg.tgrelid = tbl.oid'; 
    609         if (!is_null($table)) { 
     611        if (null !== $table) { 
    610612            $table = $db->quote(strtoupper($table), 'text'); 
    611             $query .= " AND tbl.relname = $table"; 
     613            $query .= " AND UPPER(tbl.relname) = $table"; 
    612614        } 
    613615        $result = $db->queryCol($query); 
     
    684686        } 
    685687 
     688        list($schema, $table) = $this->splitTableSchema($table); 
     689 
    686690        $table = $db->quoteIdentifier($table, true); 
     691        if (!empty($schema)) { 
     692            $table = $db->quoteIdentifier($schema, true) . '.' .$table; 
     693        } 
    687694        $db->setLimit(1); 
    688695        $result2 = $db->query("SELECT * FROM $table"); 
     
    715722        } 
    716723 
     724        list($schema, $table) = $this->splitTableSchema($table); 
     725 
    717726        $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        } 
    720737        $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)"; 
    721738        $indexes = $db->queryCol($query, 'text'); 
     
    739756 
    740757    // }}} 
     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    // }}} 
    741809    // {{{ listTableConstraints() 
    742810 
     
    755823        } 
    756824 
     825        list($schema, $table) = $this->splitTableSchema($table); 
     826 
    757827        $table = $db->quote($table, 'text'); 
    758828        $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 .= ')'; 
    762851        $constraints = $db->queryCol($query); 
    763852        if (PEAR::isError($constraints)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Manager/sqlite.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    221221     * create a new table 
    222222     * 
    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     * 
    226228     * @return mixed MDB2_OK on success, a MDB2 error on failure 
    227229     * @access public 
     
    243245                    continue; 
    244246                } 
    245                 //set actions to 'RESTRICT' if not set 
    246                 $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']); 
    248250 
    249251                $trigger_names = array( 
     
    301303                    $null_values[] = $table_fields[$i] .' = NULL'; 
    302304                } 
    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) .')'; 
    304311 
    305312                $cascade_action_update = 'UPDATE '.$name.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions); 
     
    332339                } elseif ('NO ACTION' == $fkdef['onupdate']) { 
    333340                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update') . '; END;'; 
    334                 } else { 
    335                     //'RESTRICT' 
     341                } elseif ('RESTRICT' == $fkdef['onupdate']) { 
    336342                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . '; END;'; 
    337343                } 
     
    344350                } elseif ('NO ACTION' == $fkdef['ondelete']) { 
    345351                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete')  . '; END;'; 
    346                 } else { 
    347                     //'RESTRICT' 
     352                } elseif ('RESTRICT' == $fkdef['ondelete']) { 
    348353                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . '; END;'; 
    349354                } 
     
    900905 
    901906        $query = "SELECT name FROM sqlite_master WHERE type='trigger' AND sql NOT NULL"; 
    902         if (!is_null($table)) { 
     907        if (null !== $table) { 
    903908            if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { 
    904909                $query.= ' AND LOWER(tbl_name)='.$db->quote(strtolower($table), 'text'); 
     
    11601165     * @param string $fkname FOREIGN KEY constraint name 
    11611166     * @param string $referenced_table  referenced table name 
     1167     * 
    11621168     * @return mixed MDB2_OK on success, a MDB2 error on failure 
    11631169     * @access private 
     
    11871193    } 
    11881194 
    1189     // }]] 
     1195    // }}} 
    11901196    // {{{ listTableConstraints() 
    11911197 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Native/Common.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Native/mssql.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Native/mysql.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Native/mysqli.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Native/pgsql.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747require_once 'MDB2/Driver/Native/Common.php'; 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Native/sqlite.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/Common.php

    r1352 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    7777    /** 
    7878     * 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) 
    7983     * @access private 
    8084     */ 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/mssql.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    135135        if (array_key_exists('column_default', $column)) { 
    136136            $default = $column['column_default']; 
    137             if (is_null($default) && $notnull) { 
     137            if ((null === $default) && $notnull) { 
    138138                $default = ''; 
    139139            } elseif (strlen($default) > 4 
     
    152152            'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 
    153153        ); 
    154         if (!is_null($length)) { 
     154        if (null !== $length) { 
    155155            $definition[0]['length'] = $length; 
    156156        } 
    157         if (!is_null($unsigned)) { 
     157        if (null !== $unsigned) { 
    158158            $definition[0]['unsigned'] = $unsigned; 
    159159        } 
    160         if (!is_null($fixed)) { 
     160        if (null !== $fixed) { 
    161161            $definition[0]['fixed'] = $fixed; 
    162162        } 
    163         if ($default !== false) { 
     163        if (false !== $default) { 
    164164            $definition[0]['default'] = $default; 
    165165        } 
     
    223223        $index_name_mdb2 = $db->getIndexName($index_name); 
    224224        $result = $db->queryRow(sprintf($query, $index_name_mdb2)); 
    225         if (!PEAR::isError($result) && !is_null($result)) { 
     225        if (!PEAR::isError($result) && (null !== $result)) { 
    226226            // apply 'idxname_format' only if the query succeeded, otherwise 
    227227            // fallback to the given $index_name, without transformation 
     
    321321        $constraint_name_mdb2 = $db->getIndexName($constraint_name); 
    322322        $result = $db->queryRow(sprintf($query, $constraint_name_mdb2)); 
    323         if (!PEAR::isError($result) && !is_null($result)) { 
     323        if (!PEAR::isError($result) && (null !== $result)) { 
    324324            // apply 'idxname_format' only if the query succeeded, otherwise 
    325325            // fallback to the given $index_name, without transformation 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/mysql.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    114114                if (array_key_exists('default', $column)) { 
    115115                    $default = $column['default']; 
    116                     if (is_null($default) && $notnull) { 
     116                    if ((null === $default) && $notnull) { 
    117117                        $default = ''; 
    118118                    } 
     
    132132                    'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 
    133133                ); 
    134                 if (!is_null($length)) { 
     134                if (null !== $length) { 
    135135                    $definition[0]['length'] = $length; 
    136136                } 
    137                 if (!is_null($unsigned)) { 
     137                if (null !== $unsigned) { 
    138138                    $definition[0]['unsigned'] = $unsigned; 
    139139                } 
    140                 if (!is_null($fixed)) { 
     140                if (null !== $fixed) { 
    141141                    $definition[0]['fixed'] = $fixed; 
    142142                } 
     
    147147                    $definition[0]['autoincrement'] = $autoincrement; 
    148148                } 
    149                 if (!is_null($collate)) { 
     149                if (null !== $collate) { 
    150150                    $definition[0]['collate'] = $collate; 
    151151                    $definition[0]['charset'] = $charset; 
     
    193193        $index_name_mdb2 = $db->getIndexName($index_name); 
    194194        $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)) { 
    196196            // apply 'idxname_format' only if the query succeeded, otherwise 
    197197            // fallback to the given $index_name, without transformation 
     
    270270            $constraint_name_mdb2 = $db->getIndexName($constraint_name); 
    271271            $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)) { 
    273273                // apply 'idxname_format' only if the query succeeded, otherwise 
    274274                // fallback to the given $index_name, without transformation 
     
    311311                if ($row['non_unique']) { 
    312312                    //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); 
    357314                } 
    358315                if ($row['key_name'] == 'PRIMARY') { 
     
    380337        $result->free(); 
    381338        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, 
    383407                $constraint_name . ' is not an existing table constraint', __FUNCTION__); 
    384         } 
    385         return $definition; 
    386408    } 
    387409 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/mysqli.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646// 
    4747 
     
    168168                if (array_key_exists('default', $column)) { 
    169169                    $default = $column['default']; 
    170                     if (is_null($default) && $notnull) { 
     170                    if ((null === $default) && $notnull) { 
    171171                        $default = ''; 
    172172                    } 
     
    186186                    'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 
    187187                ); 
    188                 if (!is_null($length)) { 
     188                if (null !== $length) { 
    189189                    $definition[0]['length'] = $length; 
    190190                } 
    191                 if (!is_null($unsigned)) { 
     191                if (null !== $unsigned) { 
    192192                    $definition[0]['unsigned'] = $unsigned; 
    193193                } 
    194                 if (!is_null($fixed)) { 
     194                if (null !== $fixed) { 
    195195                    $definition[0]['fixed'] = $fixed; 
    196196                } 
     
    201201                    $definition[0]['autoincrement'] = $autoincrement; 
    202202                } 
    203                 if (!is_null($collate)) { 
     203                if (null !== $collate) { 
    204204                    $definition[0]['collate'] = $collate; 
    205205                    $definition[0]['charset'] = $charset; 
     
    247247        $index_name_mdb2 = $db->getIndexName($index_name); 
    248248        $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)) { 
    250250            // apply 'idxname_format' only if the query succeeded, otherwise 
    251251            // fallback to the given $index_name, without transformation 
     
    324324            $constraint_name_mdb2 = $db->getIndexName($constraint_name); 
    325325            $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)) { 
    327327                // apply 'idxname_format' only if the query succeeded, otherwise 
    328328                // fallback to the given $index_name, without transformation 
     
    365365                if ($row['non_unique']) { 
    366366                    //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); 
    411368                } 
    412369                if ($row['key_name'] == 'PRIMARY') { 
     
    434391        $result->free(); 
    435392        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, 
    437461                $constraint_name . ' is not an existing table constraint', __FUNCTION__); 
    438         } 
    439         return $definition; 
    440462    } 
    441463 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/pgsql.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747 
    4848require_once 'MDB2/Driver/Reverse/Common.php'; 
     
    144144        $default = null; 
    145145        if ($column['atthasdef'] === 't' 
     146            && strpos($column['default'], 'NULL') !== 0 
    146147            && !preg_match("/nextval\('([^']+)'/", $column['default']) 
    147148        ) { 
    148             $pattern = '/(\'.*\')::[\w ]+$/i'; 
     149            $pattern = '/^\'(.*)\'::[\w ]+$/i'; 
    149150            $default = $column['default'];#substr($column['adsrc'], 1, -1); 
    150             if (is_null($default) && $notnull) { 
     151            if ((null === $default) && $notnull) { 
    151152                $default = ''; 
    152153            } elseif (!empty($default) && preg_match($pattern, $default)) { 
     
    160161        } 
    161162        $definition[0] = array('notnull' => $notnull, 'nativetype' => $column['type']); 
    162         if (!is_null($length)) { 
     163        if (null !== $length) { 
    163164            $definition[0]['length'] = $length; 
    164165        } 
    165         if (!is_null($unsigned)) { 
     166        if (null !== $unsigned) { 
    166167            $definition[0]['unsigned'] = $unsigned; 
    167168        } 
    168         if (!is_null($fixed)) { 
     169        if (null !== $fixed) { 
    169170            $definition[0]['fixed'] = $fixed; 
    170171        } 
     
    300301               LEFT JOIN pg_class t2 ON c.confrelid = t2.oid 
    301302                   WHERE c.conname = %s 
    302                     AND t.relname = " . $db->quote($table, 'text'); 
     303                     AND t.relname = " . $db->quote($table, 'text'); 
    303304        $constraint_name_mdb2 = $db->getIndexName($constraint_name); 
    304305        $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); 
     
    311312            return $row; 
    312313        } 
    313  
     314        $uniqueIndex = false; 
    314315        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; 
    317349        } 
    318350 
     
    336368        ); 
    337369 
     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 
    338384        $query = 'SELECT a.attname 
    339385                    FROM pg_constraint c 
     
    342388                   WHERE c.conname = %s 
    343389                     AND t.relname = ' . $db->quote($table, 'text'); 
    344         $constraint_name_mdb2 = $db->getIndexName($constraint_name); 
    345390        $fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null); 
    346391        if (PEAR::isError($fields)) { 
     
    362407                       WHERE c.conname = %s 
    363408                         AND t.relname = ' . $db->quote($definition['references']['table'], 'text'); 
    364             $constraint_name_mdb2 = $db->getIndexName($constraint_name); 
    365409            $foreign_fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null); 
    366410            if (PEAR::isError($foreign_fields)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/Reverse/sqlite.php

    r1352 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    5858class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common 
    5959{ 
     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     */ 
    6079    function _getTableColumns($sql) 
    6180    { 
     
    6988        // replace the decimal length-places-separator with a colon 
    7089        $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); 
    7292        $columns    = array(); 
    7393        $count      = count($column_sql); 
     
    7696                'unexpected empty table column definition list', __FUNCTION__); 
    7797        } 
    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'; 
    7999        $regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i'; 
    80100        for ($i=0, $j=0; $i<$count; ++$i) { 
     
    94114                $columns[$j]['decimal'] = $matches[6]; 
    95115            } 
    96             if (isset($matches[7]) && strlen($matches[7])) { 
     116            if (isset($matches[8]) && strlen($matches[8])) { 
    97117                $columns[$j]['unsigned'] = true; 
    98118            } 
    99             if (isset($matches[8]) && strlen($matches[8])) { 
     119            if (isset($matches[9]) && strlen($matches[9])) { 
    100120                $columns[$j]['autoincrement'] = true; 
    101121            } 
    102             if (isset($matches[10]) && strlen($matches[10])) { 
    103                 $default = $matches[10]; 
     122            if (isset($matches[12]) && strlen($matches[12])) { 
     123                $default = $matches[12]; 
    104124                if (strlen($default) && $default[0]=="'") { 
    105125                    $default = str_replace("''", "'", substr($default, 1, strlen($default)-2)); 
     
    110130                $columns[$j]['default'] = $default; 
    111131            } 
    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'); 
    114138            } 
    115139            ++$j; 
     
    178202                if (array_key_exists('default', $column)) { 
    179203                    $default = $column['default']; 
    180                     if (is_null($default) && $notnull) { 
     204                    if ((null === $default) && $notnull) { 
    181205                        $default = ''; 
    182206                    } 
     
    191215                    'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type']) 
    192216                ); 
    193                 if (!is_null($length)) { 
     217                if (null !== $length) { 
    194218                    $definition[0]['length'] = $length; 
    195219                } 
    196                 if (!is_null($unsigned)) { 
     220                if (null !== $unsigned) { 
    197221                    $definition[0]['unsigned'] = $unsigned; 
    198222                } 
    199                 if (!is_null($fixed)) { 
     223                if (null !== $fixed) { 
    200224                    $definition[0]['fixed'] = $fixed; 
    201225                } 
     
    277301        $end_pos = strrpos($sql, ')'); 
    278302        $column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1); 
    279         $column_names = split(',', $column_names); 
     303        $column_names = explode(',', $column_names); 
    280304 
    281305        if (preg_match("/^create unique/", $sql)) { 
     
    385409                    $definition['primary'] = true; 
    386410                    $definition['fields'] = array(); 
    387                     $column_names = split(',', $tmp[1]); 
     411                    $column_names = explode(',', $tmp[1]); 
    388412                    $colpos = 1; 
    389413                    foreach ($column_names as $column_name) { 
     
    397421                    $definition['primary'] = true; 
    398422                    $definition['fields'] = array(); 
    399                     $column_names = split(',', $tmp[1]); 
     423                    $column_names = explode(',', $tmp[1]); 
    400424                    $colpos = 1; 
    401425                    foreach ($column_names as $column_name) { 
     
    427451                    $definition['ondelete'] = 'NO ACTION'; 
    428452                    $definition['references']['table'] = $tmp[2]; 
    429                     $column_names = split(',', $tmp[1]); 
     453                    $column_names = explode(',', $tmp[1]); 
    430454                    $colpos = 1; 
    431455                    foreach ($column_names as $column_name) { 
     
    434458                        ); 
    435459                    } 
    436                     $referenced_cols = split(',', $tmp[3]); 
     460                    $referenced_cols = explode(',', $tmp[3]); 
    437461                    $colpos = 1; 
    438462                    foreach ($referenced_cols as $column_name) { 
     
    464488        $end_pos   = strrpos($sql, ')'); 
    465489        $column_names = substr($sql, $start_pos+1, $end_pos-$start_pos-1); 
    466         $column_names = split(',', $column_names); 
     490        $column_names = explode(',', $column_names); 
    467491 
    468492        if (!preg_match("/^create unique/", $sql)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/mssql.php

    r3039 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848// {{{ Class MDB2_Driver_mssql 
     
    114114    function errorInfo($error = null, $connection = null) 
    115115    { 
    116         if (is_null($connection)) { 
     116        if (null === $connection) { 
    117117            $connection = $this->connection; 
    118118        } 
     
    127127        } 
    128128        $native_msg = @mssql_get_last_message(); 
    129         if (is_null($error)) { 
     129        if (null === $error) { 
    130130            static $ecode_map; 
    131131            if (empty($ecode_map)) { 
     
    204204 
    205205    // }}} 
     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    // }}} 
    206227    // {{{ beginTransaction() 
    207228 
     
    209230     * Start a transaction or set a savepoint. 
    210231     * 
    211      * @param   string name of a savepoint to set 
    212      * @return  mixed   MDB2_OK on success, a MDB2 error on failure 
    213      * 
    214      * @access  public 
     232     * @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 
    215236     */ 
    216237    function beginTransaction($savepoint = null) 
    217238    { 
    218239        $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 
    219         if (!is_null($savepoint)) { 
     240        if (null !== $savepoint) { 
    220241            if (!$this->in_transaction) { 
    221242                return $this->raiseError(MDB2_ERROR_INVALID, null, null, 
     
    224245            $query = 'SAVE TRANSACTION '.$savepoint; 
    225246            return $this->_doQuery($query, true); 
    226         } elseif ($this->in_transaction) { 
     247        } 
     248        if ($this->in_transaction) { 
    227249            return MDB2_OK;  //nothing to do 
    228250        } 
     
    248270     * transaction is implicitly started after committing the pending changes. 
    249271     * 
    250      * @param   string name of a savepoint to release 
    251      * @return  mixed   MDB2_OK on success, a MDB2 error on failure 
    252      * 
     272     * @param string $savepoint name of a savepoint to release 
     273     * 
     274     * @return mixed MDB2_OK on success, a MDB2 error on failure 
    253275     * @access  public 
    254276     */ 
     
    260282                'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 
    261283        } 
    262         if (!is_null($savepoint)) { 
     284        if (null !== $savepoint) { 
    263285            return MDB2_OK; 
    264286        } 
     
    281303     * transaction is implicitly started after canceling the pending changes. 
    282304     * 
    283      * @param   string name of a savepoint to rollback to 
    284      * @return  mixed   MDB2_OK on success, a MDB2 error on failure 
    285      * 
    286      * @access  public 
     305     * @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 
    287309     */ 
    288310    function rollback($savepoint = null) 
     
    293315                'rollback cannot be done changes are auto committed', __FUNCTION__); 
    294316        } 
    295         if (!is_null($savepoint)) { 
     317        if (null !== $savepoint) { 
    296318            $query = 'ROLLBACK TRANSACTION '.$savepoint; 
    297319            return $this->_doQuery($query, true); 
     
    312334     * do the grunt work of the connect 
    313335     * 
     336     * @param string  $username 
     337     * @param string  $password 
     338     * @param boolean $persistent 
     339     * 
    314340     * @return connection on success or MDB2 Error Object on failure 
    315341     * @access protected 
     
    317343    function _doConnect($username, $password, $persistent = false) 
    318344    { 
    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        ) { 
    320350            return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
    321351                'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__); 
     
    326356            $username ? $username : null, 
    327357            $password ? $password : null, 
    328         ); 
     358            ); 
    329359        if ($this->dsn['port']) { 
    330360            $params[0].= ((substr(PHP_OS, 0, 3) == 'WIN') ? ',' : ':').$this->dsn['port']; 
    331361        } 
    332362        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()) { 
    336364                $params[] = true; 
    337365            } else { 
     
    350378        @mssql_query('SET ANSI_NULL_DFLT_ON ON', $connection); 
    351379 
    352 /* 
     380        /* 
    353381        if (!empty($this->dsn['charset'])) { 
    354382            $result = $this->setCharset($this->dsn['charset'], $connection); 
     
    357385            } 
    358386        } 
    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; 
    370404    } 
    371405 
     
    483517 
    484518            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; 
    487527        } 
    488528        return parent::disconnect($force); 
     
    552592        } 
    553593 
    554         if (is_null($connection)) { 
     594        if (null === $connection) { 
    555595            $connection = $this->getConnection(); 
    556596            if (PEAR::isError($connection)) { 
     
    558598            } 
    559599        } 
    560         if (is_null($database_name)) { 
     600        if (null === $database_name) { 
    561601            $database_name = $this->database_name; 
    562602        } 
     
    597637    function _affectedRows($connection, $result = null) 
    598638    { 
    599         if (is_null($connection)) { 
     639        if (null === $connection) { 
    600640            $connection = $this->getConnection(); 
    601641            if (PEAR::isError($connection)) { 
     
    787827    { 
    788828        $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']) 
    790830           && $server_info['major'] >= 8 
    791831        ) { 
     
    793833        } else { 
    794834            $query = "SELECT @@IDENTITY"; 
    795             if (!is_null($table)) { 
     835            if (null !== $table) { 
    796836                $query .= ' FROM '.$this->quoteIdentifier($table, true); 
    797837            } 
     
    850890     * Fetch a row and insert the data into an existing array. 
    851891     * 
    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     * 
    854895     * @return int data array on success, a MDB2 error on failure 
    855896     * @access public 
     
    861902            return $null; 
    862903        } 
    863         if (!is_null($rownum)) { 
     904        if (null !== $rownum) { 
    864905            $seek = $this->seek($rownum); 
    865906            if (PEAR::isError($seek)) { 
     
    881922        } 
    882923        if (!$row) { 
    883             if ($this->result === false) { 
     924            if (false === $this->result) { 
    884925                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    885926                    'resultset has already been freed', __FUNCTION__); 
     
    912953                $row = (object) $row; 
    913954            } else { 
    914                 $row = new $object_class($row); 
     955                $rowObj = new $object_class($row); 
     956                $row = $rowObj; 
    915957            } 
    916958        } 
     
    9611003    { 
    9621004        $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) { 
    9651007                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    9661008                    'resultset has already been freed', __FUNCTION__); 
    967             } elseif (is_null($this->result)) { 
     1009            } 
     1010            if (null === $this->result) { 
    9681011                return count($this->types); 
    9691012            } 
     
    9851028    function nextResult() 
    9861029    { 
    987         if ($this->result === false) { 
     1030        if (false === $this->result) { 
    9881031            return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    9891032                'resultset has already been freed', __FUNCTION__); 
    990         } elseif (is_null($this->result)) { 
     1033        } 
     1034        if (null === $this->result) { 
    9911035            return false; 
    9921036        } 
     
    10071051        if (is_resource($this->result) && $this->db->connection) { 
    10081052            $free = @mssql_free_result($this->result); 
    1009             if ($free === false) { 
     1053            if (false === $free) { 
    10101054                return $this->db->raiseError(null, null, null, 
    10111055                    'Could not free result', __FUNCTION__); 
     
    10361080     * Seek to a specific row in a result set 
    10371081     * 
    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     * 
    10391084     * @return mixed MDB2_OK on success, a MDB2 error on failure 
    10401085     * @access public 
     
    10431088    { 
    10441089        if ($this->rownum != ($rownum - 1) && !@mssql_data_seek($this->result, $rownum)) { 
    1045             if ($this->result === false) { 
     1090            if (false === $this->result) { 
    10461091                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    10471092                    'resultset has already been freed', __FUNCTION__); 
    1048             } elseif (is_null($this->result)) { 
     1093            } 
     1094            if (null === $this->result) { 
    10491095                return MDB2_OK; 
    10501096            } 
     
    10861132    { 
    10871133        $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) { 
    10901136                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    10911137                    'resultset has already been freed', __FUNCTION__); 
    1092             } elseif (is_null($this->result)) { 
     1138            } 
     1139            if (null === $this->result) { 
    10931140                return 0; 
    10941141            } 
     
    10971144        } 
    10981145        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            } 
    11001150            if ($rows < 0) { 
    11011151                $rows = 0; 
  • trunk/roundcubemail/program/lib/MDB2/Driver/mysql.php

    r3039 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    338338            register_shutdown_function('MDB2_closeOpenTransactions'); 
    339339        } 
    340         $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1'; 
     340        $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0'; 
    341341        $result =& $this->_doQuery($query, true); 
    342342        if (PEAR::isError($result)) { 
     
    391391        } 
    392392        if (!$this->start_transaction) { 
    393             $query = 'SET AUTOCOMMIT = 0'; 
     393            $query = 'SET AUTOCOMMIT = 1'; 
    394394            $result =& $this->_doQuery($query, true); 
    395395            if (PEAR::isError($result)) { 
     
    437437        } 
    438438        if (!$this->start_transaction) { 
    439             $query = 'SET AUTOCOMMIT = 0'; 
     439            $query = 'SET AUTOCOMMIT = 1'; 
    440440            $result =& $this->_doQuery($query, true); 
    441441            if (PEAR::isError($result)) { 
     
    502502 
    503503        $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 { 
    505511            $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             } 
    512512        } 
    513513        $params[] = $username ? $username : null; 
    514514        $params[] = $password ? $password : null; 
    515515        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()) { 
    519517                $params[] = true; 
    520518            } else { 
     
    626624            $charset   = array_pop($charset); 
    627625        } 
     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        } 
    628635        $query = "SET NAMES '".mysql_real_escape_string($charset, $connection)."'"; 
    629636        if (!is_null($collation)) { 
    630             $query .= " COLLATE '".mysqli_real_escape_string($connection, $collation)."'"; 
     637            $query .= " COLLATE '".mysql_real_escape_string($collation, $connection)."'"; 
    631638        } 
    632639        return $this->_doQuery($query, true, $connection); 
     
    688695 
    689696            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; 
    692705        } 
    693706        return parent::disconnect($force); 
     
    781794            ? 'mysql_query' : 'mysql_unbuffered_query'; 
    782795        $result = @$function($query, $connection); 
    783         if (!$result) { 
     796        if (!$result && 0 !== mysql_errno($connection)) { 
    784797            $err =& $this->raiseError(null, null, null, 
    785798                'Could not execute statement', __FUNCTION__); 
     
    10221035    function &prepare($query, $types = null, $result_types = null, $lobs = array()) 
    10231036    { 
     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 
    10241043        if ($this->options['emulate_prepared'] 
    10251044            || $this->supported['prepared_statements'] !== true 
     
    11001119            } 
    11011120        } 
    1102         $connection = $this->getConnection(); 
    1103         if (PEAR::isError($connection)) { 
    1104             return $connection; 
    1105         } 
     1121 
    11061122        static $prep_statement_counter = 1; 
    11071123        $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand())); 
     
    11251141     * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 
    11261142     * 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. 
    11291144     * 
    11301145     * The REPLACE type of query does not make part of the SQL standards. Since 
     
    11841199     *    Default: 0 
    11851200     * 
     1201     * @see http://dev.mysql.com/doc/refman/5.0/en/replace.html 
    11861202     * @return mixed MDB2_OK on success, a MDB2 error on failure 
    11871203     */ 
     
    13941410                $row = (object) $row; 
    13951411            } else { 
    1396                 $row = new $object_class($row); 
     1412                $rowObj = new $object_class($row); 
     1413                $row = $rowObj; 
    13971414            } 
    13981415        } 
     
    15561573        return $rows; 
    15571574    } 
     1575     
     1576    // }}} 
    15581577} 
    15591578 
     
    15741593     * @param mixed $result_class string which specifies which result class to use 
    15751594     * @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 
    15771598     * @access private 
    15781599     */ 
     
    16031624                        'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__); 
    16041625                } 
     1626                $close = false; 
    16051627                $value = $this->values[$parameter]; 
    16061628                $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null; 
  • trunk/roundcubemail/program/lib/MDB2/Driver/mysqli.php

    r3039 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    190190            $native_msg  = @mysqli_connect_error(); 
    191191        } 
    192         if (is_null($error)) { 
     192        if (null === $error) { 
    193193            static $ecode_map; 
    194194            if (empty($ecode_map)) { 
     
    321321        $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 
    322322        $this->_getServerCapabilities(); 
    323         if (!is_null($savepoint)) { 
     323        if (null !== $savepoint) { 
    324324            if (!$this->supports('savepoints')) { 
    325325                return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
     
    332332            $query = 'SAVEPOINT '.$savepoint; 
    333333            return $this->_doQuery($query, true); 
    334         } elseif ($this->in_transaction) { 
     334        } 
     335        if ($this->in_transaction) { 
    335336            return MDB2_OK;  //nothing to do 
    336337        } 
    337         $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1'; 
     338        $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0'; 
    338339        $result =& $this->_doQuery($query, true); 
    339340        if (PEAR::isError($result)) { 
     
    365366                'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 
    366367        } 
    367         if (!is_null($savepoint)) { 
     368        if (null !== $savepoint) { 
    368369            if (!$this->supports('savepoints')) { 
    369370                return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
     
    388389        } 
    389390        if (!$this->start_transaction) { 
    390             $query = 'SET AUTOCOMMIT = 0'; 
     391            $query = 'SET AUTOCOMMIT = 1'; 
    391392            $result =& $this->_doQuery($query, true); 
    392393            if (PEAR::isError($result)) { 
     
    419420                'rollback cannot be done changes are auto committed', __FUNCTION__); 
    420421        } 
    421         if (!is_null($savepoint)) { 
     422        if (null !== $savepoint) { 
    422423            if (!$this->supports('savepoints')) { 
    423424                return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
     
    434435        } 
    435436        if (!$this->start_transaction) { 
    436             $query = 'SET AUTOCOMMIT = 0'; 
     437            $query = 'SET AUTOCOMMIT = 1'; 
    437438            $result =& $this->_doQuery($query, true); 
    438439            if (PEAR::isError($result)) { 
     
    591592    function setCharset($charset, $connection = null) 
    592593    { 
    593         if (is_null($connection)) { 
     594        if (null === $connection) { 
    594595            $connection = $this->getConnection(); 
    595596            if (PEAR::isError($connection)) { 
     
    607608        ) { 
    608609            $query = "SET NAMES '".mysqli_real_escape_string($connection, $charset)."'"; 
    609             if (!is_null($collation)) { 
     610            if (null !== $collation) { 
    610611                $query .= " COLLATE '".mysqli_real_escape_string($connection, $collation)."'"; 
    611612            } 
     
    674675 
    675676            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; 
    678685        } 
    679686        return parent::disconnect($force); 
     
    743750        } 
    744751 
    745         if (is_null($connection)) { 
     752        if (null === $connection) { 
    746753            $connection = $this->getConnection(); 
    747754            if (PEAR::isError($connection)) { 
     
    749756            } 
    750757        } 
    751         if (is_null($database_name)) { 
     758        if (null === $database_name) { 
    752759            $database_name = $this->database_name; 
    753760        } 
     
    771778        } 
    772779 
    773         if (!$result) { 
     780        if (!$result && 0 !== mysqli_errno($connection)) { 
    774781            $err =& $this->raiseError(null, null, null, 
    775782                'Could not execute statement', __FUNCTION__); 
     
    808815    function _affectedRows($connection, $result = null) 
    809816    { 
    810         if (is_null($connection)) { 
     817        if (null === $connection) { 
    811818            $connection = $this->getConnection(); 
    812819            if (PEAR::isError($connection)) { 
     
    947954                } 
    948955 
    949                 // SAVEPOINTS were 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) 
    950957                if (version_compare($server_version, '4.1.0', '>=')) { 
    951958                    if (version_compare($server_version, '4.1.1', '<')) { 
     
    989996    { 
    990997        $found = strpos(strrev(substr($query, 0, $position)), '@'); 
    991         if ($found === false) { 
     998        if (false === $found) { 
    992999            return $position; 
    9931000        } 
     
    10261033    function &prepare($query, $types = null, $result_types = null, $lobs = array()) 
    10271034    { 
     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 
    10281041        if ($this->options['emulate_prepared'] 
    10291042            || $this->supported['prepared_statements'] !== true 
     
    10611074                break; 
    10621075            } 
    1063             if (is_null($placeholder_type)) { 
     1076            if (null === $placeholder_type) { 
    10641077                $placeholder_type_guess = $query[$p_position]; 
    10651078            } 
     
    10821095 
    10831096            if ($query[$position] == $placeholder_type_guess) { 
    1084                 if (is_null($placeholder_type)) { 
     1097                if (null === $placeholder_type) { 
    10851098                    $placeholder_type = $query[$p_position]; 
    10861099                    $question = $colon = $placeholder_type; 
     
    11041117            } 
    11051118        } 
    1106         $connection = $this->getConnection(); 
    1107         if (PEAR::isError($connection)) { 
    1108             return $connection; 
    1109         } 
    11101119 
    11111120        if (!$is_manip) { 
     
    11411150     * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 
    11421151     * 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. 
    11451153     * 
    11461154     * The REPLACE type of query does not make part of the SQL standards. Since 
     
    12001208     *    Default: 0 
    12011209     * 
     1210     * @see http://dev.mysql.com/doc/refman/5.0/en/replace.html 
    12021211     * @return mixed MDB2_OK on success, a MDB2 error on failure 
    12031212     */ 
     
    13581367    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 
    13591368    { 
    1360         if (!is_null($rownum)) { 
     1369        if (null !== $rownum) { 
    13611370            $seek = $this->seek($rownum); 
    13621371            if (PEAR::isError($seek)) { 
     
    13791388 
    13801389        if (!$row) { 
    1381             if ($this->result === false) { 
     1390            if (false === $this->result) { 
    13821391                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    13831392                    'resultset has already been freed', __FUNCTION__); 
     
    14101419                $row = (object) $row; 
    14111420            } else { 
    1412                 $row = new $object_class($row); 
     1421                $rowObj = new $object_class($row); 
     1422                $row = $rowObj; 
    14131423            } 
    14141424        } 
     
    14591469    { 
    14601470        $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) { 
    14631473                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    14641474                    'resultset has already been freed', __FUNCTION__); 
    1465             } elseif (is_null($this->result)) { 
     1475            } 
     1476            if (null === $this->result) { 
    14661477                return count($this->types); 
    14671478            } 
     
    15111522    function free() 
    15121523    { 
    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 
    15201534        $this->result = false; 
    15211535        return MDB2_OK; 
     
    15451559    { 
    15461560        if ($this->rownum != ($rownum - 1) && !@mysqli_data_seek($this->result, $rownum)) { 
    1547             if ($this->result === false) { 
     1561            if (false === $this->result) { 
    15481562                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    15491563                    'resultset has already been freed', __FUNCTION__); 
    1550             } elseif (is_null($this->result)) { 
     1564            } 
     1565            if (null === $this->result) { 
    15511566                return MDB2_OK; 
    15521567            } 
     
    15881603    { 
    15891604        $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) { 
    15921607                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    15931608                    'resultset has already been freed', __FUNCTION__); 
    1594             } elseif (is_null($this->result)) { 
     1609            } 
     1610            if (null === $this->result) { 
    15951611                return 0; 
    15961612            } 
     
    16471663     * @param mixed $result_class string which specifies which result class to use 
    16481664     * @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 
    16501668     * @access private 
    16511669     */ 
    16521670    function &_execute($result_class = true, $result_wrap_class = false) 
    16531671    { 
    1654         if (is_null($this->statement)) { 
     1672        if (null === $this->statement) { 
    16551673            $result =& parent::_execute($result_class, $result_wrap_class); 
    16561674            return $result; 
     
    17321750            } else { 
    17331751                $result = @call_user_func_array('mysqli_stmt_bind_param', $parameters); 
    1734                 if ($result === false) { 
     1752                if (false === $result) { 
    17351753                    $err =& $this->db->raiseError(null, null, null, 
    17361754                        'Unable to bind parameters', __FUNCTION__); 
     
    18141832    function free() 
    18151833    { 
    1816         if (is_null($this->positions)) { 
     1834        if (null === $this->positions) { 
    18171835            return $this->db->raiseError(MDB2_ERROR, null, null, 
    18181836                'Prepared statement has already been freed', __FUNCTION__); 
     
    18251843                    'Could not free statement', __FUNCTION__); 
    18261844            } 
    1827         } elseif (!is_null($this->statement)) { 
     1845        } elseif (null !== $this->statement) { 
    18281846            $connection = $this->db->getConnection(); 
    18291847            if (PEAR::isError($connection)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/pgsql.php

    r3039 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747 
    4848/** 
     
    9696        $this->options['DBA_password'] = false; 
    9797        $this->options['multi_query'] = false; 
    98         $this->options['disable_smart_seqname'] = false; 
     98        $this->options['disable_smart_seqname'] = true; 
    9999        $this->options['max_identifiers_length'] = 63; 
    100100    } 
     
    136136                    => MDB2_ERROR_NOSUCHTABLE, 
    137137                '/database .* does not exist/' 
     138                    => MDB2_ERROR_NOT_FOUND, 
     139                '/constraint .* does not exist/' 
    138140                    => MDB2_ERROR_NOT_FOUND, 
    139141                '/index .* does not exist/' 
     
    235237    { 
    236238        $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 
    237         if (!is_null($savepoint)) { 
     239        if (null !== $savepoint) { 
    238240            if (!$this->in_transaction) { 
    239241                return $this->raiseError(MDB2_ERROR_INVALID, null, null, 
     
    242244            $query = 'SAVEPOINT '.$savepoint; 
    243245            return $this->_doQuery($query, true); 
    244         } elseif ($this->in_transaction) { 
     246        } 
     247        if ($this->in_transaction) { 
    245248            return MDB2_OK;  //nothing to do 
    246249        } 
     
    278281                'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 
    279282        } 
    280         if (!is_null($savepoint)) { 
     283        if (null !== $savepoint) { 
    281284            $query = 'RELEASE SAVEPOINT '.$savepoint; 
    282285            return $this->_doQuery($query, true); 
     
    312315                'rollback cannot be done changes are auto committed', __FUNCTION__); 
    313316        } 
    314         if (!is_null($savepoint)) { 
     317        if (null !== $savepoint) { 
    315318            $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; 
    316319            return $this->_doQuery($query, true); 
     
    424427        } 
    425428 
    426         if (!empty($this->dsn['new_link']) 
    427             && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)) 
    428         { 
     429        if ($this->_isNewLinkSet()) { 
    429430            if (version_compare(phpversion(), '4.3.0', '>=')) { 
    430431                $params[] = PGSQL_CONNECT_FORCE_NEW; 
     
    450451            if (PEAR::isError($result)) { 
    451452                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                } 
    452476            } 
    453477        } 
     
    510534    function setCharset($charset, $connection = null) 
    511535    { 
    512         if (is_null($connection)) { 
     536        if (null === $connection) { 
    513537            $connection = $this->getConnection(); 
    514538            if (PEAR::isError($connection)) { 
     
    581605 
    582606            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; 
    585615        } 
    586616        return parent::disconnect($force); 
     
    654684        } 
    655685 
    656         if (is_null($connection)) { 
     686        if (null === $connection) { 
    657687            $connection = $this->getConnection(); 
    658688            if (PEAR::isError($connection)) { 
     
    692722    function _affectedRows($connection, $result = null) 
    693723    { 
    694         if (is_null($connection)) { 
     724        if (null === $connection) { 
    695725            $connection = $this->getConnection(); 
    696726            if (PEAR::isError($connection)) { 
     
    880910                break; 
    881911            } 
    882             if (is_null($placeholder_type)) { 
     912            if (null === $placeholder_type) { 
    883913                $placeholder_type_guess = $query[$p_position]; 
    884914            } 
     
    894924 
    895925            if ($query[$position] == $placeholder_type_guess) { 
    896                 if (is_null($placeholder_type)) { 
     926                if (null === $placeholder_type) { 
    897927                    $placeholder_type = $query[$p_position]; 
    898928                    $question = $colon = $placeholder_type; 
     
    953983        $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand())); 
    954984        $statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']); 
    955         if ($pgtypes === false) { 
     985        if (false === $pgtypes) { 
    956986            $result = @pg_prepare($connection, $statement_name, $query); 
    957987            if (!$result) { 
     
    10371067        } 
    10381068 
    1039         return sprintf($this->options['seqname_format'], 
    1040             preg_replace('/[^\w\$.]/i', '_', $sqn)); 
     1069        return parent::getSequenceName($sqn); 
    10411070    } 
    10421071 
     
    11381167    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 
    11391168    { 
    1140         if (!is_null($rownum)) { 
     1169        if (null !== $rownum) { 
    11411170            $seek = $this->seek($rownum); 
    11421171            if (PEAR::isError($seek)) { 
     
    11581187        } 
    11591188        if (!$row) { 
    1160             if ($this->result === false) { 
     1189            if (false === $this->result) { 
    11611190                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    11621191                    'resultset has already been freed', __FUNCTION__); 
     
    11891218                $row = (object) $row; 
    11901219            } else { 
    1191                 $row = new $object_class($row); 
     1220                $rowObj = new $object_class($row); 
     1221                $row = $rowObj; 
    11921222            } 
    11931223        } 
     
    12381268    { 
    12391269        $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) { 
    12421272                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    12431273                    'resultset has already been freed', __FUNCTION__); 
    1244             } elseif (is_null($this->result)) { 
     1274            } 
     1275            if (null === $this->result) { 
    12451276                return count($this->types); 
    12461277            } 
     
    12861317        if (is_resource($this->result) && $this->db->connection) { 
    12871318            $free = @pg_free_result($this->result); 
    1288             if ($free === false) { 
     1319            if (false === $free) { 
    12891320                return $this->db->raiseError(null, null, null, 
    12901321                    'Could not free result', __FUNCTION__); 
     
    13171348    { 
    13181349        if ($this->rownum != ($rownum - 1) && !@pg_result_seek($this->result, $rownum)) { 
    1319             if ($this->result === false) { 
     1350            if (false === $this->result) { 
    13201351                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    13211352                    'resultset has already been freed', __FUNCTION__); 
    1322             } elseif (is_null($this->result)) { 
     1353            } 
     1354            if (null === $this->result) { 
    13231355                return MDB2_OK; 
    13241356            } 
     
    13601392    { 
    13611393        $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) { 
    13641396                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    13651397                    'resultset has already been freed', __FUNCTION__); 
    1366             } elseif (is_null($this->result)) { 
     1398            } 
     1399            if (null === $this->result) { 
    13671400                return 0; 
    13681401            } 
     
    13901423     * @param mixed $result_class string which specifies which result class to use 
    13911424     * @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 
    13931428     * @access private 
    13941429     */ 
    13951430    function &_execute($result_class = true, $result_wrap_class = false) 
    13961431    { 
    1397         if (is_null($this->statement)) { 
     1432        if (null === $this->statement) { 
    13981433            $result =& parent::_execute($result_class, $result_wrap_class); 
    13991434            return $result; 
     
    14911526    function free() 
    14921527    { 
    1493         if (is_null($this->positions)) { 
     1528        if (null === $this->positions) { 
    14941529            return $this->db->raiseError(MDB2_ERROR, null, null, 
    14951530                'Prepared statement has already been freed', __FUNCTION__); 
     
    14971532        $result = MDB2_OK; 
    14981533 
    1499         if (!is_null($this->statement)) { 
     1534        if (null !== $this->statement) { 
    15001535            $connection = $this->db->getConnection(); 
    15011536            if (PEAR::isError($connection)) { 
  • trunk/roundcubemail/program/lib/MDB2/Driver/sqlite.php

    r3039 r3227  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    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 $ 
    4747// 
    4848 
     
    132132        $native_msg = preg_replace('/^sqlite[a-z_]+\(\)[^:]*: /', '', $native_msg); 
    133133 
    134         if (is_null($error)) { 
     134        if (null === $error) { 
    135135            static $error_regexps; 
    136136            if (empty($error_regexps)) { 
     
    195195    { 
    196196        $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); 
    197         if (!is_null($savepoint)) { 
     197        if (null !== $savepoint) { 
    198198            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
    199199                'savepoints are not supported', __FUNCTION__); 
    200         } elseif ($this->in_transaction) { 
     200        } 
     201        if ($this->in_transaction) { 
    201202            return MDB2_OK;  //nothing to do 
    202203        } 
     
    235236                'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); 
    236237        } 
    237         if (!is_null($savepoint)) { 
     238        if (null !== $savepoint) { 
    238239            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
    239240                'savepoints are not supported', __FUNCTION__); 
     
    270271                'rollback cannot be done changes are auto committed', __FUNCTION__); 
    271272        } 
    272         if (!is_null($savepoint)) { 
     273        if (null !== $savepoint) { 
    273274            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 
    274275                'savepoints are not supported', __FUNCTION__); 
     
    365366        } 
    366367 
    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                } 
    369390                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__); 
    389393                } 
    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 
    430433        return MDB2_OK; 
    431434    } 
     
    480483                @sqlite_close($this->connection); 
    481484            } 
     485        } else { 
     486            return false; 
    482487        } 
    483488        return parent::disconnect($force); 
    484     } 
    485  
    486     // }}} 
    487     // {{{ getConnection() 
    488  
    489     /** 
    490      * Returns a native connection 
    491      * 
    492      * @return  mixed   a valid MDB2 connection object, 
    493      *                  or a MDB2 error object on error 
    494      * @access  public 
    495      */ 
    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; 
    510489    } 
    511490 
     
    537516        } 
    538517 
    539         if (is_null($connection)) { 
     518        if (null === $connection) { 
    540519            $connection = $this->getConnection(); 
    541520            if (PEAR::isError($connection)) { 
     
    583562    function _affectedRows($connection, $result = null) 
    584563    { 
    585         if (is_null($connection)) { 
     564        if (null === $connection) { 
    586565            $connection = $this->getConnection(); 
    587566            if (PEAR::isError($connection)) { 
     
    674653     * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT 
    675654     * 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. 
    678656     * 
    679657     * The REPLACE type of query does not make part of the SQL standards. Since 
     
    899877    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 
    900878    { 
    901         if (!is_null($rownum)) { 
     879        if (null !== $rownum) { 
    902880            $seek = $this->seek($rownum); 
    903881            if (PEAR::isError($seek)) { 
     
    919897        } 
    920898        if (!$row) { 
    921             if ($this->result === false) { 
     899            if (false === $this->result) { 
    922900                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    923901                    'resultset has already been freed', __FUNCTION__); 
     
    950928                $row = (object) $row; 
    951929            } else { 
    952                 $row = new $object_class($row); 
     930                $rowObj = new $object_class($row); 
     931                $row = $rowObj; 
    953932            } 
    954933        } 
     
    999978    { 
    1000979        $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) { 
    1003982                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    1004983                    'resultset has already been freed', __FUNCTION__); 
    1005             } elseif (is_null($this->result)) { 
     984            } 
     985            if (null === $this->result) { 
    1006986                return count($this->types); 
    1007987            } 
     
    10341014    { 
    10351015        if (!@sqlite_seek($this->result, $rownum)) { 
    1036             if ($this->result === false) { 
     1016            if (false === $this->result) { 
    10371017                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    10381018                    'resultset has already been freed', __FUNCTION__); 
    1039             } elseif (is_null($this->result)) { 
     1019            } 
     1020            if (null === $this->result) { 
    10401021                return MDB2_OK; 
    10411022            } 
     
    10771058    { 
    10781059        $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) { 
    10811062                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    10821063                    'resultset has already been freed', __FUNCTION__); 
    1083             } elseif (is_null($this->result)) { 
     1064            } 
     1065            if (null === $this->result) { 
    10841066                return 0; 
    10851067            } 
     
    11021084 
    11031085} 
    1104  
    11051086?> 
  • trunk/roundcubemail/program/lib/MDB2/Extended.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747/** 
     
    215215        } 
    216216 
    217         if ($where !== false && !is_null($where)) { 
     217        if ((false !== $where) && (null !== $where)) { 
    218218            if (is_array($where)) { 
    219219                $where = implode(' AND ', $where); 
  • trunk/roundcubemail/program/lib/MDB2/Iterator.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747/** 
  • trunk/roundcubemail/program/lib/MDB2/LOB.php

    r1002 r3227  
    4343// +----------------------------------------------------------------------+ 
    4444// 
    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 $ 
    4646 
    4747/** 
Note: See TracChangeset for help on using the changeset viewer.