Skip to content

Commit

Permalink
Merge branch '3.1/release/3.1.3' into 3.1/master
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed May 2, 2011
2 parents 82a47ba + 82709bc commit 0ba6065
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 67 deletions.
8 changes: 7 additions & 1 deletion classes/kohana/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,18 @@ abstract public function connect();

/**
* Disconnect from the database. This is called automatically by [Database::__destruct].
* Clears the database instance from [Database::$instances].
*
* $db->disconnect();
*
* @return boolean
*/
abstract public function disconnect();
public function disconnect()
{
unset(Database::$instances[$this->_instance]);

return TRUE;
}

/**
* Set the connection character set. This is called automatically by [Database::connect].
Expand Down
34 changes: 1 addition & 33 deletions classes/kohana/database/exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,4 @@
* @copyright (c) 2009 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Database_Exception extends Kohana_Exception {

protected $db_code = NULL;

/**
* Creates a new translated database exception.
*
* throw new Database_Exception(1234, 'Something went terrible wrong, :user',
* array(':user' => $user));
*
* @param string raw DB error code
* @param string error message
* @param array translation variables
* @param integer the exception code
* @return void
*/
public function __construct($db_code, $message, array $variables = NULL, $code = 0)
{
$this->db_code = $db_code;

parent::__construct($message, $variables, $code);
}

/**
* Gets the DB error code
*
* @return string
*/
public function db_code()
{
return $this->db_code;
}
}
class Kohana_Database_Exception extends Kohana_Exception {}
44 changes: 21 additions & 23 deletions classes/kohana/database/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public function connect()
// No connection exists
$this->_connection = NULL;

throw new Database_Exception(mysql_errno(), '[:code] :error', array(
':code' => mysql_errno(),
':error' => mysql_error(),
));
throw new Database_Exception(':error',
array(':error' => mysql_error()),
mysql_errno());
}

// \xFF is a better delimiter, but the PHP driver uses underscore
Expand All @@ -93,10 +92,9 @@ protected function _select_db($database)
if ( ! mysql_select_db($database, $this->_connection))
{
// Unable to select database
throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
));
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
}

Database_MySQL::$_current_databases[$this->_connection_id] = $database;
Expand All @@ -115,6 +113,9 @@ public function disconnect()
{
// Clear the connection
$this->_connection = NULL;

// Clear the instance
parent::disconnect();
}
}
}
Expand Down Expand Up @@ -145,10 +146,9 @@ public function set_charset($charset)

if ($status === FALSE)
{
throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
));
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
}
}

Expand Down Expand Up @@ -178,11 +178,9 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
Profiler::delete($benchmark);
}

throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error ( :query )', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
':query' => $sql,
));
throw new Database_Exception(':error [ :query ]',
array(':error' => mysql_error($this->_connection), ':query' => $sql),
mysql_errno($this->_connection));
}

if (isset($benchmark))
Expand Down Expand Up @@ -275,8 +273,9 @@ public function begin($mode = NULL)

if ($mode AND ! mysql_query("SET TRANSACTION ISOLATION LEVEL $mode", $this->_connection))
{
throw new Database_Exception(mysql_errno($this->_connection), ':error', array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
}

return (bool) mysql_query('START TRANSACTION', $this->_connection);
Expand Down Expand Up @@ -421,10 +420,9 @@ public function escape($value)

if (($value = mysql_real_escape_string( (string) $value, $this->_connection)) === FALSE)
{
throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
));
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
}

// SQL standard is to use single-quotes for all values
Expand Down
20 changes: 10 additions & 10 deletions classes/kohana/database/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ public function connect()
}
catch (PDOException $e)
{
throw new Database_Exception($e->getCode(), '[:code] :error', array(
':code' => $e->getMessage(),
':error' => $e->getCode(),
), $e->getCode());
throw new Database_Exception(':error',
array(':error' => $e->getMessage()),
$e->getCode());
}

if ( ! empty($this->_config['charset']))
Expand All @@ -74,7 +73,7 @@ public function disconnect()
// Destroy the PDO object
$this->_connection = NULL;

return TRUE;
return parent::disconnect();
}

public function set_charset($charset)
Expand Down Expand Up @@ -110,11 +109,12 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
}

// Convert the exception in a database exception
throw new Database_Exception($e->getCode(), '[:code] :error ( :query )', array(
':code' => $e->getMessage(),
':error' => $e->getCode(),
':query' => $sql,
), $e->getCode());
throw new Database_Exception(':error [ :query ]',
array(
':error' => $e->getMessage(),
':query' => $sql
),
$e->getCode());
}

if (isset($benchmark))
Expand Down

0 comments on commit 0ba6065

Please sign in to comment.