1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-12 09:04:24 +02:00

* modified DibiException (getDbError, ...)

* fix dibi::dumpResult()
This commit is contained in:
David Grudl
2007-02-02 03:51:43 +00:00
parent a2b1036a66
commit 0c86515076
16 changed files with 218 additions and 138 deletions

View File

@@ -49,9 +49,9 @@ abstract class DibiDriver
/**
* DibiDriver factory: creates object and connects to a database
*
* @param array connect configuration
* @param array connect configuration
* @return DibiDriver
* @throw DibiException
* @throw DibiException
*/
/*abstract disallowed since PHP 5.2*/ static public function connect($config) {}

View File

@@ -28,31 +28,44 @@ if (!defined('DIBI')) die();
class DibiException extends Exception
{
private
$info;
$sql,
$dbError;
public function __construct($message, $info=NULL) {
$this->info = $info;
if (isset($info['message']))
$message = "$message: $info[message]";
public function __construct($message, $dbError=NULL, $sql=NULL)
{
$this->dbError = $dbError;
$this->sql = $sql;
parent::__construct($message);
}
public function getSql()
{
return isset($this->info['sql']) ? $this->info['sql'] : NULL;
return $this->sql;
}
public function getDbError()
{
return $this->dbError;
}
public function __toString()
{
$s = parent::__toString();
if (isset($this->info['sql']))
$s .= "\nSQL: " . $this->info['sql'];
if ($this->dbError) {
$s .= "\nERROR: ";
if (isset($this->dbError['code']))
$s .= "[" . $this->dbError['code'] . "] ";
$s .= $this->dbError['message'];
}
if ($this->sql) $s .= "\nSQL: " . $this->sql;
return $s;
}

View File

@@ -200,6 +200,11 @@ abstract class DibiResult implements IteratorAggregate, Countable
return array(); // empty resultset
$assocBy = func_get_args();
// check function parameters - !!! ignore or throw error?
foreach ($assocBy as $n => $assoc) //
if (!array_key_exists($assoc, $rec)) unset($assocBy[$n]);
$arr = array();
do { // make associative arrays
@@ -234,6 +239,9 @@ abstract class DibiResult implements IteratorAggregate, Countable
if (!$rec)
return array(); // empty resultset
if (!array_key_exists($key, $rec) ||
!array_key_exists($value, $rec)) return FALSE;
$arr = array();
do {
$arr[ $rec[$key] ] = $rec[$value];

View File

@@ -52,7 +52,7 @@ class DibiTranslator
*
* @param array
* @return string
* @throw DibiException
* @throw DibiException
*/
public function translate($args)
{
@@ -115,10 +115,6 @@ class DibiTranslator
$this->sql = $sql;
return !$this->hasError;
if ($this->hasError)
throw new DibiException('Errors during generating SQL', array('sql' => $sql));
return $sql;
}