1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-18 03:41:30 +02:00

* new exceptions: BadMethodCallException, InvalidArgumentException

* DibiMySqlDriver, DibiMySqliDriver, DibiSqliteDriver, DibiOracleDriver: error checking instead of FALSE checking in doQuery
This commit is contained in:
David Grudl
2007-11-08 03:32:37 +00:00
parent 453cc9be13
commit 25fa4293fc
12 changed files with 34 additions and 47 deletions

View File

@@ -14,7 +14,7 @@
* @author David Grudl
* @copyright Copyright (c) 2005, 2007 David Grudl
* @license http://php7.org/dibi/license (dibi license)
* @version 0.9a (Revision: $WCREV$, Date: $WCDATE$)
* @version 0.9b (Revision: $WCREV$, Date: $WCDATE$)
* @category Database
* @package Dibi
* @link http://php7.org/dibi/
@@ -24,13 +24,10 @@
/**
* Check PHP configuration
*/
if (version_compare(PHP_VERSION , '5.0.3', '<')) {
throw new Exception('dibi needs PHP 5.0.3 or newer');
if (version_compare(PHP_VERSION , '5.1.0', '<')) {
throw new Exception('dibi needs PHP 5.1.0 or newer');
}
if (preg_match('#on$|true$|yes$|[+-]?0*[1-9]#iA', ini_get('zend.ze1_compatibility_mode'))) {
throw new Exception('dibi cannot run with zend.ze1_compatibility_mode enabled');
}
@@ -91,7 +88,7 @@ class dibi
FIELD_COUNTER = 'c', // counter or autoincrement, is integer
// dibi version
VERSION = '0.9a (Revision: $WCREV$, Date: $WCDATE$)';
VERSION = '0.9b (Revision: $WCREV$, Date: $WCDATE$)';
/**
@@ -400,11 +397,12 @@ class dibi
*
* @param callback
* @return void
* @throws InvalidArgumentException
*/
public static function addHandler($callback)
{
if (!is_callable($callback)) {
throw new DibiException("Invalid callback");
throw new InvalidArgumentException("Invalid callback");
}
self::$handlers[] = $callback;

View File

@@ -99,7 +99,7 @@ class DibiMsSqlDriver extends DibiDriver
public function insertId()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -157,7 +157,7 @@ class DibiMsSqlDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -173,7 +173,7 @@ class DibiMsSqlDriver extends DibiDriver
}
if ($offset) {
throw new DibiException('Offset is not implemented');
throw new InvalidArgumentException('Offset is not implemented');
}
}

View File

@@ -115,8 +115,8 @@ class DibiMySqlDriver extends DibiDriver
$connection = $this->getConnection();
$res = @mysql_query($sql, $connection);
if ($res === FALSE) {
throw new DibiDatabaseException(mysql_error($connection), mysql_errno($connection), $sql);
if ($errno = mysql_errno($connection)) {
throw new DibiDatabaseException(mysql_error($connection), $errno, $sql);
}
return is_resource($res) ? new DibiMySqlResult($res) : TRUE;
@@ -194,7 +194,7 @@ class DibiMySqlDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}

View File

@@ -89,8 +89,8 @@ class DibiMySqliDriver extends DibiDriver
$connection = $this->getConnection();
$res = @mysqli_query($connection, $sql);
if ($res === FALSE) {
throw new DibiDatabaseException(mysqli_error($connection), mysqli_errno($connection), $sql);
if ($errno = mysqli_errno($connection)) {
throw new DibiDatabaseException(mysqli_error($connection), $errno, $sql);
}
return is_object($res) ? new DibiMySqliResult($res) : TRUE;
@@ -179,7 +179,7 @@ class DibiMySqliDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}

View File

@@ -122,7 +122,7 @@ class DibiOdbcDriver extends DibiDriver
public function insertId()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -192,7 +192,7 @@ class DibiOdbcDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -207,7 +207,7 @@ class DibiOdbcDriver extends DibiDriver
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')';
}
if ($offset) throw new DibiException('Offset is not implemented in driver odbc');
if ($offset) throw new InvalidArgumentException('Offset is not implemented in driver odbc');
}

View File

@@ -80,8 +80,8 @@ class DibiOracleDriver extends DibiDriver
$statement = oci_parse($connection, $sql);
if ($statement) {
$res = oci_execute($statement, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
if (!$res) {
$err = oci_error($statement);
$err = oci_error($statement);
if ($err) {
throw new DibiDatabaseException($err['message'], $err['code'], $sql);
}
} else {
@@ -97,14 +97,14 @@ class DibiOracleDriver extends DibiDriver
public function affectedRows()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
public function insertId()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -167,7 +167,7 @@ class DibiOracleDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -210,7 +210,7 @@ class DibiOracleResult extends DibiResult
public function seek($row)
{
//throw new DibiException(__METHOD__ . ' is not implemented');
//throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}

View File

@@ -76,7 +76,7 @@ class DibiPdoDriver extends DibiDriver
public function affectedRows()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -127,7 +127,7 @@ class DibiPdoDriver extends DibiDriver
public function escape($value, $appendQuotes = TRUE)
{
if (!$appendQuotes) {
throw new DibiException('Escaping without qoutes is not supported by PDO');
throw new BadMethodCallException('Escaping without qoutes is not supported by PDO');
}
return $this->getConnection()->quote($value);
}
@@ -144,7 +144,7 @@ class DibiPdoDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
@@ -154,7 +154,7 @@ class DibiPdoDriver extends DibiDriver
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}
} // class DibiPdoDriver

View File

@@ -191,7 +191,7 @@ class DibiPostgreDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}

View File

@@ -79,9 +79,8 @@ class DibiSqliteDriver extends DibiDriver
$connection = $this->getConnection();
$res = @sqlite_query($connection, $sql, SQLITE_ASSOC);
if ($res === FALSE) {
$code = sqlite_last_error($connection);
throw new DibiDatabaseException(sqlite_error_string($code), $code, $sql);
if ($errno = sqlite_last_error($connection)) {
throw new DibiDatabaseException(sqlite_error_string($errno), $errno, $sql);
}
return is_resource($res) ? new DibiSqliteResult($res) : TRUE;
@@ -158,7 +157,7 @@ class DibiSqliteDriver extends DibiDriver
public function getMetaData()
{
throw new DibiException(__METHOD__ . ' is not implemented');
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
}

View File

@@ -21,16 +21,6 @@
// PHP < 5.1 compatibility
if (!interface_exists('Countable', FALSE)) {
interface Countable
{
function count();
}
}
/**
* dibi result-set abstract class
*