Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge remote-tracking branch 'origin/3.2/develop' into 3.2/feature/30…

…00-config-rewrite
  • Loading branch information...
commit afa336591f6472ac7af49f253833cf2377a76672 2 parents ca7056f + f7ce165
Matt Button BRMatt authored
10 classes/kohana/database.php
@@ -62,7 +62,7 @@ public static function instance($name = NULL, array $config = NULL)
62 62 if ($config === NULL)
63 63 {
64 64 // Load the configuration for this database
65   - $config = Kohana::config('database')->$name;
  65 + $config = Kohana::$config->load('database')->$name;
66 66 }
67 67
68 68 if ( ! isset($config['type']))
@@ -158,12 +158,18 @@ protected function __construct($name, array $config)
158 158
159 159 /**
160 160 * Disconnect from the database. This is called automatically by [Database::__destruct].
  161 + * Clears the database instance from [Database::$instances].
161 162 *
162 163 * $db->disconnect();
163 164 *
164 165 * @return boolean
165 166 */
166   - abstract public function disconnect();
  167 + public function disconnect()
  168 + {
  169 + unset(Database::$instances[$this->_instance]);
  170 +
  171 + return TRUE;
  172 + }
167 173
168 174 /**
169 175 * Set the connection character set. This is called automatically by [Database::connect].
34 classes/kohana/database/exception.php
@@ -8,36 +8,4 @@
8 8 * @copyright (c) 2009 Kohana Team
9 9 * @license http://kohanaphp.com/license
10 10 */
11   -class Kohana_Database_Exception extends Kohana_Exception {
12   -
13   - protected $db_code = NULL;
14   -
15   - /**
16   - * Creates a new translated database exception.
17   - *
18   - * throw new Database_Exception(1234, 'Something went terrible wrong, :user',
19   - * array(':user' => $user));
20   - *
21   - * @param string raw DB error code
22   - * @param string error message
23   - * @param array translation variables
24   - * @param integer the exception code
25   - * @return void
26   - */
27   - public function __construct($db_code, $message, array $variables = NULL, $code = 0)
28   - {
29   - $this->db_code = $db_code;
30   -
31   - parent::__construct($message, $variables, $code);
32   - }
33   -
34   - /**
35   - * Gets the DB error code
36   - *
37   - * @return string
38   - */
39   - public function db_code()
40   - {
41   - return $this->db_code;
42   - }
43   -}
  11 +class Kohana_Database_Exception extends Kohana_Exception {}
44 classes/kohana/database/mysql.php
@@ -64,10 +64,9 @@ public function connect()
64 64 // No connection exists
65 65 $this->_connection = NULL;
66 66
67   - throw new Database_Exception(mysql_errno(), '[:code] :error', array(
68   - ':code' => mysql_errno(),
69   - ':error' => mysql_error(),
70   - ));
  67 + throw new Database_Exception(':error',
  68 + array(':error' => mysql_error()),
  69 + mysql_errno());
71 70 }
72 71
73 72 // \xFF is a better delimiter, but the PHP driver uses underscore
@@ -93,10 +92,9 @@ protected function _select_db($database)
93 92 if ( ! mysql_select_db($database, $this->_connection))
94 93 {
95 94 // Unable to select database
96   - throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
97   - ':code' => mysql_errno($this->_connection),
98   - ':error' => mysql_error($this->_connection),
99   - ));
  95 + throw new Database_Exception(':error',
  96 + array(':error' => mysql_error($this->_connection)),
  97 + mysql_errno($this->_connection));
100 98 }
101 99
102 100 Database_MySQL::$_current_databases[$this->_connection_id] = $database;
@@ -115,6 +113,9 @@ public function disconnect()
115 113 {
116 114 // Clear the connection
117 115 $this->_connection = NULL;
  116 +
  117 + // Clear the instance
  118 + parent::disconnect();
118 119 }
119 120 }
120 121 }
@@ -145,10 +146,9 @@ public function set_charset($charset)
145 146
146 147 if ($status === FALSE)
147 148 {
148   - throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
149   - ':code' => mysql_errno($this->_connection),
150   - ':error' => mysql_error($this->_connection),
151   - ));
  149 + throw new Database_Exception(':error',
  150 + array(':error' => mysql_error($this->_connection)),
  151 + mysql_errno($this->_connection));
152 152 }
153 153 }
154 154
@@ -178,11 +178,9 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
178 178 Profiler::delete($benchmark);
179 179 }
180 180
181   - throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error ( :query )', array(
182   - ':code' => mysql_errno($this->_connection),
183   - ':error' => mysql_error($this->_connection),
184   - ':query' => $sql,
185   - ));
  181 + throw new Database_Exception(':error [ :query ]',
  182 + array(':error' => mysql_error($this->_connection), ':query' => $sql),
  183 + mysql_errno($this->_connection));
186 184 }
187 185
188 186 if (isset($benchmark))
@@ -275,8 +273,9 @@ public function begin($mode = NULL)
275 273
276 274 if ($mode AND ! mysql_query("SET TRANSACTION ISOLATION LEVEL $mode", $this->_connection))
277 275 {
278   - throw new Database_Exception(mysql_errno($this->_connection), ':error', array(':error' => mysql_error($this->_connection)),
279   - mysql_errno($this->_connection));
  276 + throw new Database_Exception(':error',
  277 + array(':error' => mysql_error($this->_connection)),
  278 + mysql_errno($this->_connection));
280 279 }
281 280
282 281 return (bool) mysql_query('START TRANSACTION', $this->_connection);
@@ -421,10 +420,9 @@ public function escape($value)
421 420
422 421 if (($value = mysql_real_escape_string( (string) $value, $this->_connection)) === FALSE)
423 422 {
424   - throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
425   - ':code' => mysql_errno($this->_connection),
426   - ':error' => mysql_error($this->_connection),
427   - ));
  423 + throw new Database_Exception(':error',
  424 + array(':error' => mysql_error($this->_connection)),
  425 + mysql_errno($this->_connection));
428 426 }
429 427
430 428 // SQL standard is to use single-quotes for all values
20 classes/kohana/database/pdo.php
@@ -56,10 +56,9 @@ public function connect()
56 56 }
57 57 catch (PDOException $e)
58 58 {
59   - throw new Database_Exception($e->getCode(), '[:code] :error', array(
60   - ':code' => $e->getMessage(),
61   - ':error' => $e->getCode(),
62   - ), $e->getCode());
  59 + throw new Database_Exception(':error',
  60 + array(':error' => $e->getMessage()),
  61 + $e->getCode());
63 62 }
64 63
65 64 if ( ! empty($this->_config['charset']))
@@ -74,7 +73,7 @@ public function disconnect()
74 73 // Destroy the PDO object
75 74 $this->_connection = NULL;
76 75
77   - return TRUE;
  76 + return parent::disconnect();
78 77 }
79 78
80 79 public function set_charset($charset)
@@ -110,11 +109,12 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
110 109 }
111 110
112 111 // Convert the exception in a database exception
113   - throw new Database_Exception($e->getCode(), '[:code] :error ( :query )', array(
114   - ':code' => $e->getMessage(),
115   - ':error' => $e->getCode(),
116   - ':query' => $sql,
117   - ), $e->getCode());
  112 + throw new Database_Exception(':error [ :query ]',
  113 + array(
  114 + ':error' => $e->getMessage(),
  115 + ':query' => $sql
  116 + ),
  117 + $e->getCode());
118 118 }
119 119
120 120 if (isset($benchmark))
10 classes/kohana/database/query/builder.php
@@ -180,16 +180,10 @@ protected function _compile_order_by(Database $db, array $columns)
180 180 if ($direction)
181 181 {
182 182 // Make the direction uppercase
183   - $direction = strtoupper($direction);
  183 + $direction = ' '.strtoupper($direction);
184 184 }
185 185
186   - if ($column)
187   - {
188   - // Quote the column, if it has a value
189   - $column = $db->quote_column($column);
190   - }
191   -
192   - $sort[] = trim($column.' '.$direction);
  186 + $sort[] = $db->quote_column($column).$direction;
193 187 }
194 188
195 189 return 'ORDER BY '.implode(', ', $sort);
2  guide/database/examples.md
Source Rendered
@@ -28,7 +28,7 @@ In this example, we loop through an array of whitelisted input fields and for ea
28 28 $count = $pagination_query->select('COUNT("*") AS mycount')->execute()->get('mycount');
29 29
30 30 //pass the total item count to Pagination
31   - $config = Kohana::config('pagination');
  31 + $config = Kohana::$config->load('pagination');
32 32 $pagination = Pagination::factory(array(
33 33 'total_items' => $count,
34 34 'current_page' => array('source' => 'route', 'key' => 'page'),

0 comments on commit afa3365

Please sign in to comment.
Something went wrong with that request. Please try again.