mirror of
https://github.com/dg/dibi.git
synced 2025-08-11 08:34:59 +02:00
* added support for affectedRows in DibiPdoDriver
This commit is contained in:
@@ -387,7 +387,7 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
|
||||
*
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
protected function throwException($sql=NULL)
|
||||
protected function throwException($sql = NULL)
|
||||
{
|
||||
throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection), $sql);
|
||||
}
|
||||
|
@@ -362,7 +362,7 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
|
||||
*
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
protected function throwException($sql=NULL)
|
||||
protected function throwException($sql = NULL)
|
||||
{
|
||||
throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection), $sql);
|
||||
}
|
||||
|
@@ -339,7 +339,7 @@ class DibiOdbcDriver extends NObject implements DibiDriverInterface
|
||||
*
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
protected function throwException($sql=NULL)
|
||||
protected function throwException($sql = NULL)
|
||||
{
|
||||
throw new DibiDriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection), 0, $sql);
|
||||
}
|
||||
|
@@ -296,7 +296,7 @@ class DibiOracleDriver extends NObject implements DibiDriverInterface
|
||||
*
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
protected function throwException($sql=NULL)
|
||||
protected function throwException($sql = NULL)
|
||||
{
|
||||
$err = oci_error($this->connection);
|
||||
throw new DibiDriverException($err['message'], $err['code'], $sql);
|
||||
|
@@ -50,6 +50,13 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
||||
private $resultset;
|
||||
|
||||
|
||||
/**
|
||||
* Affected rows
|
||||
* @var int
|
||||
*/
|
||||
private $affectedRows = FALSE;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connects to a database
|
||||
@@ -101,13 +108,30 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
$this->resultset = $this->connection->query($sql);
|
||||
// must detect if SQL returns resultset or num of affected rows
|
||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
||||
$list = array('UPDATE'=>1, 'DELETE'=>1, 'INSERT'=>1, 'REPLAC'=>1);
|
||||
|
||||
if ($this->resultset === FALSE) {
|
||||
$this->throwException($sql);
|
||||
if (isset($list[$cmd])) {
|
||||
$this->resultset = NULL;
|
||||
$this->affectedRows = $this->connection->exec($sql);
|
||||
|
||||
if ($this->affectedRows === FALSE) {
|
||||
$this->throwException($sql);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
$this->resultset = $this->connection->query($sql);
|
||||
$this->affectedRows = FALSE;
|
||||
|
||||
if ($this->resultset === FALSE) {
|
||||
$this->throwException($sql);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $this->resultset instanceof PDOStatement;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +143,7 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
||||
*/
|
||||
public function affectedRows()
|
||||
{
|
||||
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
|
||||
return $this->affectedRows;
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +310,7 @@ class DibiPdoDriver extends NObject implements DibiDriverInterface
|
||||
*
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
protected function throwException($sql=NULL)
|
||||
protected function throwException($sql = NULL)
|
||||
{
|
||||
$err = $this->connection->errorInfo();
|
||||
throw new DibiDriverException("SQLSTATE[$err[0]]: $err[2]", $err[1], $sql);
|
||||
|
Reference in New Issue
Block a user