Changeset 848

Show
Ignore:
Timestamp:
10/18/2007 10:36:47 PM (12 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()
Location:
trunk
Files:
10 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/config/config.php

    r843 r848  
    6868$config['include_paths'] = array 
    6969( 
    70         'modules/user_guide' 
     70        'modules/user_guide', 
     71        'modules/orm' 
    7172); 
    7273 
  • trunk/system/core/Kohana.php

    r846 r848  
    10121012                foreach($params as $var) 
    10131013                { 
    1014                         $output[] = '<pre>'.print_r($var, TRUE).'<pre>'; 
     1014                        $output[] = '<pre>'.print_r($var, TRUE).'</pre>'; 
    10151015                } 
    10161016 
  • 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(); 
  • trunk/system/libraries/Profiler.php

    r816 r848  
    5353                ( 
    5454                        'benchmarks' => array(), 
    55                         'queries'    => FALSE 
     55                        'queries'    => Database::$benchmarks 
    5656                ); 
    5757 
     
    6060                { 
    6161                        $data['benchmarks'][str_replace(SYSTEM_BENCHMARK.'_', '', $name)] = $time; 
    62                 } 
    63  
    64                 // Get database queries 
    65                 if (isset(Kohana::instance()->db)) 
    66                 { 
    67                         $data['queries'] = Database::$benchmarks; 
    6862                } 
    6963 
  • trunk/system/libraries/drivers/Database_Mysql.php

    r829 r848  
    6060                        } 
    6161 
    62                         return TRUE; 
     62                        return $this->link; 
    6363                } 
    6464