Development

Changeset 6011

You must first sign up to be able to contribute.

Changeset 6011

Show
Ignore:
Timestamp:
11/14/07 11:33:25 (2 years ago)
Author:
fabien
Message:

partially reverted changes in r6005

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/Creole.php

    r6006 r6011  
    269269     * The format of the supplied DSN is in its fullest form: 
    270270     * 
    271      *  phptype://username:password@hostspec/database 
     271     *  phptype://username:password@protocol+hostspec/database 
    272272     * 
    273273     * Most variations are allowed: 
    274274     * 
    275      *  phptype://username:password@protocol(hostspec:110)//usr/db_file.db 
     275     *  phptype://username:password@protocol+hostspec:110//usr/db_file.db 
    276276     *  phptype://username:password@hostspec/database_name 
    277277     *  phptype://username:password@hostspec 
     
    301301        ); 
    302302 
    303     $preg_query = "!^(([a-z0-9]+)(\(([^()]+)\))?)(://((((([^@/:]+)(:([^@/]*))?)@)?((([a-z]+)\((([^?():]+)(:([^()?]+))?)\))|((([^/?:]+)(:([^/?]+))?))))/?)?([^?]+)?(\?(.+))?)?$!i"; 
    304      
    305     $info = array(); 
    306      
    307     if (preg_match($preg_query,$dsn,$info)) { // only if it is matching 
    308              
    309       $parsed['phptype'] = @$info[2]; // Group 2 should always exist. 
    310        
    311       // Don't know what to do with Group 4: phptype(xx) should => check first if available 
    312        
    313       if (isset($info[5])) { // There is more than just the phptype 
    314          
    315         if (strlen($info[10]) > 0) { // There is a username specified 
    316           $parsed['username'] = @$info[10]; 
    317         } 
    318          
    319         if (strlen($info[12]) > 0) { // There is a password specified 
    320           $parsed['password'] = @$info[12]; 
    321         } 
    322          
    323         if (strlen($info[15]) > 0) { // There is a protocol specified: protocol(hostspec) 
    324           $parsed['protocol'] = @$info[15]; 
    325            
    326           if ($parsed["protocol"] === "unix") { 
    327             $parsed['socket'] = @$info[16]; 
    328           } else { 
    329             $parsed["hostspec"] = @$info[17]; 
    330             if (strlen($info[19]) > 0) { 
    331               $parsed["port"] = @$info[19]; 
    332             } 
    333           } 
    334         } elseif (strlen($info[20]) > 0) { 
    335           $parsed["hostspec"] = @$info[22]; 
    336            
    337           if ((isset($info[24]) && (strlen($info[24]) > 0))) { // There is a port set (not always available)  
    338             $parsed["port"] = @$info[24]; 
    339           } 
    340         } 
    341          
    342         if ((isset($info[25])) && (strlen($info[25]) > 0)) { // There is a database 
    343           $parsed["database"] = @$info[25]; 
    344         } 
    345          
    346         if ((isset($info[27])) && (strlen($info[27]) >0)) { // There is a query 
    347           $opts = explode('&', $info[27]); 
    348           foreach ($opts as $opt) { 
    349             list($key, $value) = explode('=', $opt); 
    350             if (!isset($parsed[$key])) { // don't allow params overwrite 
    351               $parsed[$key] = urldecode($value); 
    352             } 
    353           }  
    354         } 
    355          
    356       } 
    357     }  
     303        $info = parse_url($dsn); 
     304 
     305        if (count($info) === 1) { // if there's only one element in result, then it must be the phptype 
     306            $parsed['phptype'] = array_pop($info); 
     307            return $parsed; 
     308        } 
     309 
     310        // some values can be copied directly 
     311        $parsed['phptype'] = @$info['scheme']; 
     312        $parsed['username'] = @$info['user']; 
     313        $parsed['password'] = @$info['pass']; 
     314        $parsed['port'] = @$info['port']; 
     315 
     316        $host = @$info['host']; 
     317        if (false !== ($pluspos = strpos($host, '+'))) { 
     318            $parsed['protocol'] = substr($host,0,$pluspos); 
     319            if ($parsed['protocol'] === 'unix') { 
     320                $parsed['socket'] = substr($host,$pluspos+1); 
     321            } else { 
     322                $parsed['hostspec'] = substr($host,$pluspos+1); 
     323            } 
     324        } else { 
     325            $parsed['hostspec'] = $host; 
     326        } 
     327 
     328        if (isset($info['path'])) { 
     329            $parsed['database'] = substr($info['path'], 1); // remove first char, which is '/' 
     330        } 
     331 
     332        if (isset($info['query'])) { 
     333                $opts = explode('&', $info['query']); 
     334                foreach ($opts as $opt) { 
     335                    list($key, $value) = explode('=', $opt); 
     336                    if (!isset($parsed[$key])) { // don't allow params overwrite 
     337                        $parsed[$key] = urldecode($value); 
     338                    } 
     339                } 
     340        } 
    358341 
    359342        return $parsed; 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/CreoleTypes.php

    r6005 r6011  
    122122         * @return int Creole native type (e.g. Types::LONGVARCHAR, Types::BINARY, etc.). 
    123123         */ 
    124         abstract static function getType($nativeType); 
     124        public static function getType($nativeType) { 
     125          throw new Exception('This method must be overridden in subclasses!'); // abstract static not allowed since PHP 5.2 
     126        } 
    125127         
    126128        /** 
     
    131133         * @return string Native type string. 
    132134         */ 
    133         abstract static function getNativeType($creoleType); 
     135        public static function getNativeType($creoleType) { 
     136           throw new Exception('This method must be overridden in subclasses!'); // abstract static not allowed since PHP 5.2 
     137        } 
    134138         
    135139        /** 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/mysql/MySQLResultSet.php

    r6005 r6011  
    9494    function close() 
    9595    {         
    96         @mysql_free_result($this->result); 
     96        if(is_resource($this->result)) 
     97            @mysql_free_result($this->result); 
    9798        $this->fields = array(); 
    9899    }     
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/mysqli/MySQLiConnection.php

    r6005 r6011  
    3333 */ 
    3434class MySQLiConnection extends ConnectionCommon implements Connection { 
     35    /** Current database (used in mysqli_select_db()). */ 
     36    private $database; 
    3537 
    3638    /** 
     
    7880    $conn = mysqli_connect($host, $user, $pw, $database, $port, $socket); 
    7981 
    80         @ini_restore('track_errors'); 
    81  
    82         if (!$conn) { 
     82            @ini_restore('track_errors'); 
     83 
     84        if (empty($conn)) { 
    8385            if (($err = @mysqli_error()) != '') { 
    8486                throw new SQLException("connect failed", $err); 
     
    8991            } 
    9092        } 
    91          
     93 
     94        if ($dsninfo['database']) { 
     95            if (!@mysqli_select_db($conn, $dsninfo['database'])) { 
     96               switch(mysqli_errno($conn)) { 
     97                        case 1049: 
     98                            $exc = new SQLException("no such database", mysqli_error($conn)); 
     99                        break; 
     100                        case 1044: 
     101                            $exc = new SQLException("access violation", mysqli_error($conn)); 
     102                        break; 
     103                        default: 
     104                           $exc = new SQLException("cannot select database", mysqli_error($conn)); 
     105                } 
     106 
     107                throw $exc; 
     108 
     109            } 
     110 
     111            // fix to allow calls to different databases in the same script 
     112            $this->database = $dsninfo['database']; 
     113        } 
     114 
    92115        $this->dblink = $conn; 
    93116 
     
    169192        $this->lastQuery = $sql; 
    170193 
     194        if ($this->database) { 
     195            if (!@mysqli_select_db($this->dblink, $this->database)) { 
     196                throw new SQLException('No database selected', mysqli_error($this->dblink)); 
     197            } 
     198        } 
     199 
    171200        $result = @mysqli_query($this->dblink, $sql); 
    172201 
     
    185214        $this->lastQuery = $sql; 
    186215 
     216        if ($this->database) { 
     217            if (!@mysqli_select_db($this->dblink, $this->database)) { 
     218                    throw new SQLException('No database selected', mysqli_error($this->dblink)); 
     219            } 
     220        } 
     221 
    187222        $result = @mysqli_query($this->dblink, $sql); 
    188223 
     
    213248    protected function commitTrans() 
    214249    { 
     250        if ($this->database) { 
     251            if (!@mysqli_select_db($this->dblink, $this->database)) { 
     252                 throw new SQLException('No database selected', mysqli_error($this->dblink)); 
     253            } 
     254        } 
     255 
    215256        if (!mysqli_commit($this->dblink)) { 
    216257            throw new SQLException('Can not commit transaction', mysqli_error($this->dblink));                 
     
    227268    protected function rollbackTrans() 
    228269    { 
     270        if ($this->database) { 
     271            if (!@mysqli_select_db($this->dblink, $this->database)) { 
     272                throw new SQLException('No database selected', mysqli_error($this->dblink)); 
     273            } 
     274        } 
     275 
    229276        if (!mysqli_rollback($this->dblink)) { 
    230277            throw new SQLException('Could not rollback transaction', mysqli_error($this->dblink)); 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/mysqli/metadata/MySQLiTableInfo.php

    r6005 r6011  
    3535        require_once 'creole/metadata/ColumnInfo.php'; 
    3636        require_once 'creole/drivers/mysql/MySQLTypes.php'; 
     37 
     38        if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) { 
     39            throw new SQLException('No database selected'); 
     40        } 
    3741 
    3842        // To get all of the attributes we need, we use 
     
    8791        } 
    8892 
     93        if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) { 
     94            throw new SQLException('No database selected'); 
     95        } 
     96 
    8997        // Primary Keys 
    9098        $res = mysqli_query($this->conn->getResource(), "SHOW KEYS FROM " . $this->name); 
     
    112120            $this->initColumns(); 
    113121        } 
    114          
     122 
     123        if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) { 
     124            throw new SQLException('No database selected'); 
     125        } 
     126 
    115127        // Indexes 
    116128        $res = mysqli_query($this->conn->getResource(), "SHOW INDEX FROM " . $this->name); 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/oracle/OCI8Connection.php

    r6005 r6011  
    7070        $pw           = $dsninfo[ 'password' ]; 
    7171        $hostspec       = $dsninfo[ 'hostspec' ]; 
     72        $port       = $dsninfo[ 'port' ]; 
    7273        $db         = $dsninfo[ 'database' ]; 
    7374 
     
    7576                  ? 'oci_pconnect' 
    7677                  : 'oci_connect'; 
     78    $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null; 
     79 
     80    @ini_set( 'track_errors', true ); 
    7781     
    78     $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null; 
    79  
    80     @ini_set( 'track_errors', true ); 
     82    if ( $hostspec && $port ) 
     83    { 
     84      $hostspec .= ':' . $port; 
     85    } 
    8186 
    8287        if ( $db && $hostspec && $user && $pw ) 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/oracle/OCI8Types.php

    r6005 r6011  
    4545                                'raw' => CreoleTypes::VARBINARY, 
    4646                                'longraw' => CreoleTypes::LONGVARBINARY, 
    47                                 'date' => CreoleTypes::TIMESTAMP, 
     47                                'date' => CreoleTypes::DATE, 
     48                                'timestamp' => CreoleTypes::TIMESTAMP, 
    4849                                'blob' => CreoleTypes::BLOB, 
    4950                                'clob' => CreoleTypes::CLOB, 
     
    6263    public static function getType($nativeType) 
    6364    { 
    64         $t = strtolower($nativeType); 
     65        $t = str_replace(' ', '', strtolower($nativeType)); 
     66        if ( substr($t, 0, 9) == 'timestamp' ) return CreoleTypes::TIMESTAMP; 
    6567        if (isset(self::$typeMap[$t])) { 
    6668            return self::$typeMap[$t]; 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/sqlite/SQLiteResultSet.php

    r6005 r6011  
    116116    { 
    117117        $this->fields = array(); 
     118        $this->result = null; 
    118119    } 
    119120} 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/sqlite/metadata/SQLiteTableInfo.php

    r6005 r6011  
    4343        // the second will fill in some more details. 
    4444         
    45         $sql = 'PRAGMA table_info('.$this->name.')'
     45        $sql = "PRAGMA table_info('".$this->name."')"
    4646                 
    4747        $res = sqlite_query($this->conn->getResource(), $sql); 
     
    6767                $type = $fulltype; 
    6868            } 
    69              
     69            // If column is primary key and of type INTEGER, it is auto increment 
     70            // See: http://sqlite.org/faq.html#q1 
     71            $is_auto_increment = ($row['pk'] == 1 && $fulltype == 'INTEGER'); 
    7072            $not_null = $row['notnull']; 
    7173            $is_nullable = !$not_null; 
     
    104106        if (!$this->colsLoaded) $this->initColumns();         
    105107 
    106         $sql = 'PRAGMA index_list('.$this->name.')'
     108        $sql = "PRAGMA index_list('".$this->name."')"
    107109        $res = sqlite_query($this->conn->getResource(), $sql); 
    108110         
     
    112114             
    113115            // get columns for that index 
    114             $res2 = sqlite_query($this->conn->getResource(), 'PRAGMA index_info('.$name.')'); 
     116            $res2 = sqlite_query($this->conn->getResource(), "PRAGMA index_info('$name')"); 
    115117            while($row2 = sqlite_fetch_array($res2, SQLITE_ASSOC)) { 
    116118                $colname = $row2['name']; 
  • trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/metadata/DatabaseInfo.php

    r6005 r6011  
    140140  public function hasTable($name) 
    141141  { 
     142    if(!$this->tablesLoaded) $this->initTables(); 
    142143    return isset($this->tables[strtoupper($name)]); 
    143144  } 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.