mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 21:28:02 +02:00
- added parameter $name in dibi::getConnection()
- bug fixed error handling in SQlite driver
This commit is contained in:
@@ -14,11 +14,11 @@
|
|||||||
* @license GNU GENERAL PUBLIC LICENSE v2
|
* @license GNU GENERAL PUBLIC LICENSE v2
|
||||||
* @package dibi
|
* @package dibi
|
||||||
* @category Database
|
* @category Database
|
||||||
* @version 0.7f $Revision$ $Date$
|
* @version 0.7g $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
define('DIBI', 'Version 0.7f $Revision$');
|
define('DIBI', 'Version 0.7g $Revision$');
|
||||||
|
|
||||||
|
|
||||||
if (version_compare(PHP_VERSION , '5.0.3', '<'))
|
if (version_compare(PHP_VERSION , '5.0.3', '<'))
|
||||||
@@ -145,7 +145,7 @@ class dibi
|
|||||||
* @return void
|
* @return void
|
||||||
* @throw DibiException
|
* @throw DibiException
|
||||||
*/
|
*/
|
||||||
static public function connect($config, $name = '1')
|
static public function connect($config, $name='1')
|
||||||
{
|
{
|
||||||
// DSN string
|
// DSN string
|
||||||
if (is_string($config))
|
if (is_string($config))
|
||||||
@@ -188,15 +188,23 @@ class dibi
|
|||||||
/**
|
/**
|
||||||
* Retrieve active connection
|
* Retrieve active connection
|
||||||
*
|
*
|
||||||
|
* @param string connection registy name
|
||||||
* @return object DibiDriver object.
|
* @return object DibiDriver object.
|
||||||
* @throw DibiException
|
* @throw DibiException
|
||||||
*/
|
*/
|
||||||
static public function getConnection()
|
static public function getConnection($name=NULL)
|
||||||
{
|
{
|
||||||
if (!self::$conn)
|
if ($name === NULL) {
|
||||||
throw new DibiException('Dibi is not connected to database');
|
if (!self::$conn)
|
||||||
|
throw new DibiException('Dibi is not connected to database');
|
||||||
|
|
||||||
return self::$conn;
|
return self::$conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset(self::$registry[$name]))
|
||||||
|
throw new DibiException("There is no connection named '$name'.");
|
||||||
|
|
||||||
|
return self::$registry[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -210,11 +218,7 @@ class dibi
|
|||||||
*/
|
*/
|
||||||
static public function activate($name)
|
static public function activate($name)
|
||||||
{
|
{
|
||||||
if (!isset(self::$registry[$name]))
|
self::$conn = self::getConnection($name);
|
||||||
throw new DibiException("There is no connection named '$name'.");
|
|
||||||
|
|
||||||
// change active connection
|
|
||||||
self::$conn = self::$registry[$name];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -29,8 +29,7 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
private
|
private
|
||||||
$conn,
|
$conn,
|
||||||
$insertId = FALSE,
|
$insertId = FALSE,
|
||||||
$affectedRows = FALSE,
|
$affectedRows = FALSE;
|
||||||
$errorMsg;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
$formats = array(
|
$formats = array(
|
||||||
@@ -75,8 +74,7 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
{
|
{
|
||||||
$this->insertId = $this->affectedRows = FALSE;
|
$this->insertId = $this->affectedRows = FALSE;
|
||||||
|
|
||||||
$this->errorMsg = '';
|
$res = @sqlite_query($this->conn, $sql, SQLITE_ASSOC);
|
||||||
$res = @sqlite_query($this->conn, $sql, SQLITE_ASSOC, $this->errorMsg);
|
|
||||||
|
|
||||||
if ($res === FALSE) return FALSE;
|
if ($res === FALSE) return FALSE;
|
||||||
|
|
||||||
@@ -125,9 +123,10 @@ class DibiSqliteDriver extends DibiDriver
|
|||||||
|
|
||||||
public function errorInfo()
|
public function errorInfo()
|
||||||
{
|
{
|
||||||
|
$code = sqlite_last_error($this->conn);
|
||||||
return array(
|
return array(
|
||||||
'message' => $this->errorMsg,
|
'message' => sqlite_error_string($code),
|
||||||
'code' => NULL,
|
'code' => $code,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@ class DibiException extends Exception
|
|||||||
{
|
{
|
||||||
$this->dbError = $dbError;
|
$this->dbError = $dbError;
|
||||||
$this->sql = $sql;
|
$this->sql = $sql;
|
||||||
|
|
||||||
parent::__construct($message);
|
parent::__construct($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ class DibiException extends Exception
|
|||||||
$s = parent::__toString();
|
$s = parent::__toString();
|
||||||
|
|
||||||
if ($this->dbError) {
|
if ($this->dbError) {
|
||||||
$s .= "\nERROR: ";
|
$s .= "\n\nDatabase error: ";
|
||||||
if (isset($this->dbError['code']))
|
if (isset($this->dbError['code']))
|
||||||
$s .= "[" . $this->dbError['code'] . "] ";
|
$s .= "[" . $this->dbError['code'] . "] ";
|
||||||
|
|
||||||
|
@@ -1 +1 @@
|
|||||||
Dibi Version 0.7f
|
Dibi Version 0.7g
|
||||||
|
Reference in New Issue
Block a user