Show
Ignore:
Timestamp:
10/18/2007 10:36:47 PM (14 months ago)
Author:
Shadowhand
Message:

Small fixes:

  • Added ORM example at /orm/
  • Fixed the syntax of Kohana::debug_output()
  • Moved Database benchmarks to Database::query()
  • Fixed profiler to handle new Database benchmark (static) location
  • Database drivers now return the database connection resource instead of TRUE when calling connect()
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Database.php

    r832 r848  
    4141        // Database driver object 
    4242        protected $driver; 
     43        protected $link; 
    4344 
    4445        // Un-compiled parts of the SQL query 
     
    5657        protected $limit      = FALSE; 
    5758        protected $offset     = FALSE; 
    58         protected $connected  = FALSE; 
    5959        protected $last_query = ''; 
    6060 
     
    8484                        { 
    8585                                $name = $config; 
    86                                  
     86 
    8787                                // Test the config group name 
    8888                                if (($config = Config::item('database.'.$config)) === FALSE) 
     
    194194        public function connect() 
    195195        { 
    196                 $this->connected = $this->driver->connect($this->config); 
    197  
    198                 if ($this->connected != TRUE) 
    199                         throw new Kohana_Exception('database.connection', $this->driver->show_error()); 
     196                if ( ! is_resource($this->link)) 
     197                { 
     198                        if ( ! is_resource($this->link = $this->driver->connect($this->config))) 
     199                                throw new Kohana_Exception('database.connection', $this->driver->show_error()); 
     200                } 
    200201        } 
    201202 
     
    211212                if ($sql == '') return FALSE; 
    212213 
    213                 if ( ! $this->connected) $this->connect(); 
     214                // No link? Connect! 
     215                $this->link or $this->connect(); 
     216 
     217                // Start the benchmark 
     218                $start = microtime(TRUE); 
    214219 
    215220                if (func_num_args() > 1) //if we have more than one argument ($sql) 
     
    218223                        $binds = (is_array(next($argv))) ? current($argv) : $argv; 
    219224                } 
     225 
    220226                // Compile binds if needed 
    221227                if (isset($binds)) 
     
    223229                        $sql = $this->compile_binds($sql, $binds); 
    224230                } 
    225                 $this->last_query = $sql; 
    226                 return $this->driver->query($sql); 
     231 
     232                // Fetch the result 
     233                $result = $this->driver->query($this->last_query = $sql); 
     234 
     235                // Stop the benchmark 
     236                $stop = microtime(TRUE); 
     237 
     238                if ($this->config['benchmark'] == TRUE) 
     239                { 
     240                        // Benchmark the query 
     241                        self::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start); 
     242                } 
     243 
     244                return $result; 
    227245        } 
    228246 
     
    540558                $sql = $this->driver->compile_select(get_object_vars($this)); 
    541559 
    542                 $start = microtime(TRUE); 
    543560                $result = $this->query($sql); 
    544                 $stop = microtime(TRUE); 
    545  
    546                 if ($this->config['benchmark'] == TRUE) 
    547                 { 
    548                         // Benchmark the query 
    549                         self::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start); 
    550                 } 
    551561 
    552562                $this->reset_select();