1
0
mirror of https://github.com/dg/dibi.git synced 2025-10-20 17:32:50 +02:00

* seek() or rowCount() in unbuffered mode throws exceptions

* out of range seek() throws exception
* deprecated DibiDriver::errorInfo
* fixed seek(0) on first iteration
* added DibiDatabaseException::catchError() & restore() for converting errors to exceptions
This commit is contained in:
David Grudl
2007-11-12 01:39:26 +00:00
parent 5ee6a19f93
commit ea00d5d37d
14 changed files with 184 additions and 223 deletions

View File

@@ -103,27 +103,16 @@ class DibiMySqlDriver extends DibiDriver
$host = ':' . $config['socket'];
}
// some errors aren't handled. Must use $php_errormsg
if (function_exists('ini_set')) {
$save = ini_set('track_errors', TRUE);
}
$php_errormsg = '';
DibiDatabaseException::catchError();
if (empty($config['persistent'])) {
$connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['options']);
} else {
$connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['options']);
}
if (function_exists('ini_set')) {
ini_set('track_errors', $save);
}
DibiDatabaseException::restore();
if (!is_resource($connection)) {
$msg = mysql_error();
if (!$msg) $msg = $php_errormsg;
throw new DibiDatabaseException($msg, mysql_errno());
throw new DibiDatabaseException(mysql_error(), mysql_errno());
}
if (isset($config['charset'])) {
@@ -163,17 +152,18 @@ class DibiMySqlDriver extends DibiDriver
{
$connection = $this->getConnection();
if ($this->getConfig('unbuffered')) {
$res = @mysql_unbuffered_query($sql, $connection);
} else {
$buffered = !$this->getConfig('unbuffered');
if ($buffered) {
$res = @mysql_query($sql, $connection);
} else {
$res = @mysql_unbuffered_query($sql, $connection);
}
if ($errno = mysql_errno($connection)) {
throw new DibiDatabaseException(mysql_error($connection), $errno, $sql);
}
return is_resource($res) ? new DibiMySqlResult($res) : NULL;
return is_resource($res) ? new DibiMySqlResult($res, $buffered) : NULL;
}
@@ -240,22 +230,6 @@ class DibiMySqlDriver extends DibiDriver
/**
* Returns last error
*
* @return array with items 'message' and 'code'
*/
public function errorInfo()
{
$connection = $this->getConnection();
return array(
'message' => mysql_error($connection),
'code' => mysql_errno($connection),
);
}
/**
* Escapes the string
*
@@ -342,7 +316,7 @@ class DibiMySqlResult extends DibiResult
*
* @return int
*/
public function rowCount()
protected function doRowCount()
{
return mysql_num_rows($this->resource);
}
@@ -366,11 +340,14 @@ class DibiMySqlResult extends DibiResult
* Moves cursor position without fetching row
*
* @param int the 0-based cursor pos to seek to
* @return boolean TRUE on success, FALSE if unable to seek to specified record
* @return void
* @throws DibiException
*/
public function seek($row)
protected function doSeek($row)
{
return mysql_data_seek($this->resource, $row);
if (!mysql_data_seek($this->resource, $row)) {
throw new DibiDriverException('Unable to seek to row ' . $row);
}
}
@@ -380,7 +357,7 @@ class DibiMySqlResult extends DibiResult
*
* @return void
*/
protected function free()
protected function doFree()
{
mysql_free_result($this->resource);
}