1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 14:16:39 +02:00

fixed some bugs

This commit is contained in:
David Grudl
2007-11-12 14:35:55 +00:00
parent 46850aa588
commit d19eb5b815
8 changed files with 47 additions and 43 deletions

View File

@@ -266,7 +266,7 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
public function rowCount() public function rowCount()
{ {
if (!$this->buffered) { if (!$this->buffered) {
throw new BadMethodCallException(__METHOD__ . ' is not allowed for unbuffered queries'); throw new DibiDatabaseException('Row count is not available for unbuffered queries');
} }
return mysql_num_rows($this->resultset); return mysql_num_rows($this->resultset);
} }
@@ -296,8 +296,9 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
public function seek($row) public function seek($row)
{ {
if (!$this->buffered) { if (!$this->buffered) {
throw new BadMethodCallException(__METHOD__ . ' is not allowed for unbuffered queries'); throw new DibiDatabaseException('Cannot seek an unbuffered result set');
} }
if (!mysql_data_seek($this->resultset, $row)) { if (!mysql_data_seek($this->resultset, $row)) {
throw new DibiDatabaseException('Unable to seek to row ' . $row); throw new DibiDatabaseException('Unable to seek to row ' . $row);
} }

View File

@@ -251,7 +251,7 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
public function rowCount() public function rowCount()
{ {
if (!$this->buffered) { if (!$this->buffered) {
throw new BadMethodCallException(__METHOD__ . ' is not allowed for unbuffered queries'); throw new DibiDatabaseException('Row count is not available for unbuffered queries');
} }
return mysqli_num_rows($this->resultset); return mysqli_num_rows($this->resultset);
} }
@@ -281,7 +281,7 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
public function seek($row) public function seek($row)
{ {
if (!$this->buffered) { if (!$this->buffered) {
throw new BadMethodCallException(__METHOD__ . ' is not allowed for unbuffered queries'); throw new DibiDatabaseException('Cannot seek an unbuffered result set');
} }
if (!mysqli_data_seek($this->resultset, $row)) { if (!mysqli_data_seek($this->resultset, $row)) {
throw new DibiDatabaseException('Unable to seek to row ' . $row); throw new DibiDatabaseException('Unable to seek to row ' . $row);

View File

@@ -85,7 +85,7 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
} }
if (!is_resource($this->connection)) { if (!is_resource($this->connection)) {
throw new DibiDatabaseException(odbc_errormsg(), odbc_error()); throw new DibiDatabaseException(odbc_errormsg() . ' ' . odbc_error());
} }
} }
@@ -112,11 +112,10 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
*/ */
public function query($sql) public function query($sql)
{ {
$this->affectedRows = FALSE;
$this->resultset = @odbc_exec($this->connection, $sql); $this->resultset = @odbc_exec($this->connection, $sql);
if ($this->resultset === FALSE) { if ($this->resultset === FALSE) {
throw new DibiDatabaseException(odbc_errormsg($this->connection), odbc_error($this->connection), $sql); throw new DibiDatabaseException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection), 0, $sql);
} }
return is_resource($this->resultset); return is_resource($this->resultset);
@@ -155,7 +154,7 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
public function begin() public function begin()
{ {
if (!odbc_autocommit($this->connection, FALSE)) { if (!odbc_autocommit($this->connection, FALSE)) {
throw new DibiDatabaseException(odbc_errormsg($this->connection), odbc_error($this->connection)); throw new DibiDatabaseException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
} }
} }
@@ -168,7 +167,7 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
public function commit() public function commit()
{ {
if (!odbc_commit($this->connection)) { if (!odbc_commit($this->connection)) {
throw new DibiDatabaseException(odbc_errormsg($this->connection), odbc_error($this->connection)); throw new DibiDatabaseException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
} }
odbc_autocommit($this->connection, TRUE); odbc_autocommit($this->connection, TRUE);
} }
@@ -182,7 +181,7 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
public function rollback() public function rollback()
{ {
if (!odbc_rollback($this->connection)) { if (!odbc_rollback($this->connection)) {
throw new DibiDatabaseException(odbc_errormsg($this->connection), odbc_error($this->connection)); throw new DibiDatabaseException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
} }
odbc_autocommit($this->connection, TRUE); odbc_autocommit($this->connection, TRUE);
} }
@@ -285,11 +284,6 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
/** this is experimental */ /** this is experimental */
public function buildMeta() public function buildMeta()
{ {
// cache
if ($meta !== NULL) {
return $meta;
}
static $types = array( static $types = array(
'CHAR' => dibi::FIELD_TEXT, 'CHAR' => dibi::FIELD_TEXT,
'COUNTER' => dibi::FIELD_COUNTER, 'COUNTER' => dibi::FIELD_COUNTER,

View File

@@ -244,7 +244,6 @@ class DibiOracleDriver extends NObject implements DibiDriverInterface
*/ */
public function fetch() public function fetch()
{ {
$this->fetched = TRUE;
return oci_fetch_assoc($this->resultset); return oci_fetch_assoc($this->resultset);
} }
@@ -259,7 +258,6 @@ class DibiOracleDriver extends NObject implements DibiDriverInterface
*/ */
public function seek($row) public function seek($row)
{ {
if ($row === 0 && !$this->fetched) return TRUE;
throw new BadMethodCallException(__METHOD__ . ' is not implemented'); throw new BadMethodCallException(__METHOD__ . ' is not implemented');
} }

View File

@@ -231,6 +231,7 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
*/ */
public function seek($row) public function seek($row)
{ {
$this->row = $row;
} }

View File

@@ -224,7 +224,7 @@ class DibiSqliteDriver extends NObject implements DibiDriverInterface
public function rowCount() public function rowCount()
{ {
if (!$this->buffered) { if (!$this->buffered) {
throw new BadMethodCallException(__METHOD__ . ' is not allowed for unbuffered queries'); throw new DibiDatabaseException('Row count is not available for unbuffered queries');
} }
return sqlite_num_rows($this->resultset); return sqlite_num_rows($this->resultset);
} }
@@ -254,11 +254,11 @@ class DibiSqliteDriver extends NObject implements DibiDriverInterface
public function seek($row) public function seek($row)
{ {
if (!$this->buffered) { if (!$this->buffered) {
throw new BadMethodCallException(__METHOD__ . ' is not allowed for unbuffered queries'); throw new DibiDatabaseException('Cannot seek an unbuffered result set');
}
if (!sqlite_seek($this->resultset, $row)) {
throw new DibiDatabaseException('Unable to seek to row ' . $row);
} }
DibiDatabaseException::catchError();
sqlite_seek($this->resultset, $row);
DibiDatabaseException::restore();
} }

View File

@@ -51,7 +51,7 @@ class DibiDatabaseException extends DibiException
public function __construct($message = NULL, $code = 0, $sql = NULL) public function __construct($message = NULL, $code = 0, $sql = NULL)
{ {
parent::__construct($message); parent::__construct($message, (int) $code);
$this->sql = $sql; $this->sql = $sql;
dibi::notify(NULL, 'exception', $this); dibi::notify(NULL, 'exception', $this);
} }

View File

@@ -52,19 +52,19 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
* Describes columns types * Describes columns types
* @var array * @var array
*/ */
protected $convert; private $convert;
/** /**
* Describes columns types * Describes columns types
* @var array * @var array
*/ */
protected $meta; private $meta;
/** /**
* Already fetched? Used for allowance for first seek(0) * Already fetched? Used for allowance for first seek(0)
* @var bool * @var bool
*/ */
protected $fetched = FALSE; private $fetched = FALSE;
@@ -86,6 +86,18 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
} }
/**
* Automatically frees the resources allocated for this result set
*
* @return void
*/
public function __destruct()
{
@$this->driver->free();
}
/** /**
* Returns the resultset resource * Returns the resultset resource
* *
@@ -107,11 +119,9 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
*/ */
final public function seek($row) final public function seek($row)
{ {
if ($row === 0 && !$this->fetched) { if ($row !== 0 || $this->fetched) {
return TRUE; $this->driver->seek($row);
} }
$this->driver->seek($row);
} }
@@ -128,6 +138,18 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
/**
* Frees the resources allocated for this result set
*
* @return void
*/
final public function free()
{
$this->driver->free();
}
/** /**
* Fetches the row at current position, process optional type conversion * Fetches the row at current position, process optional type conversion
* and moves the internal cursor to the next position * and moves the internal cursor to the next position
@@ -334,18 +356,6 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
/**
* Automatically frees the resources allocated for this result set
*
* @return void
*/
public function __destruct()
{
@$this->driver->free();
}
final public function setType($field, $type = NULL) final public function setType($field, $type = NULL)
{ {
if ($field === TRUE) { if ($field === TRUE) {
@@ -438,7 +448,7 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
* *
* @return void * @return void
*/ */
public function dump() final public function dump()
{ {
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n"; echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";