1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-13 01:24:06 +02:00

* added dibi::date & dibi::datetime

* DibiConnection::insertId && affectedRows throws exception on failure
* added protected throwException() to drivers
* DibiPostgreDriver - can build connection string
* DibiSqliteDriver - support for parameters 'format:date' & 'format:datetime'
* fixed query errors in DibiSqliteDriver
* DibiConnection prevents serialization and multiple transactions
This commit is contained in:
David Grudl
2007-11-23 23:27:14 +00:00
parent 3f42b2cf55
commit 7c6947a019
18 changed files with 419 additions and 176 deletions

View File

@@ -29,7 +29,7 @@
* - 'password' (or 'pass')
* - 'persistent' - try to find a persistent link?
* - 'database' - the database name to select
* - 'charset' - sets the encoding
* - 'charset' - character encoding to set
* - 'unbuffered' - sends query without fetching and buffering the result rows automatically?
* - 'options' - driver specific constants (MYSQLI_*)
* - 'lazy' - if TRUE, connection will be established only when required
@@ -130,7 +130,7 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
$this->resultset = @mysqli_query($this->connection, $sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT);
if ($errno = mysqli_errno($this->connection)) {
throw new DibiDriverException(mysqli_error($this->connection), $errno, $sql);
$this->throwException($sql);
}
return is_object($this->resultset);
@@ -141,7 +141,7 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
/**
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
*
* @return int number of rows or FALSE on error
* @return int|FALSE number of rows or FALSE on error
*/
public function affectedRows()
{
@@ -165,11 +165,12 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
/**
* Begins a transaction (if supported).
* @return void
* @throws DibiDriverException
*/
public function begin()
{
if (!mysqli_autocommit($this->connection, FALSE)) {
throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection));
$this->throwException($sql);
}
}
@@ -178,11 +179,12 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
/**
* Commits statements in a transaction.
* @return void
* @throws DibiDriverException
*/
public function commit()
{
if (!mysqli_commit($this->connection)) {
throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection));
$this->throwException($sql);
}
mysqli_autocommit($this->connection, TRUE);
}
@@ -192,11 +194,12 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
/**
* Rollback changes in a transaction.
* @return void
* @throws DibiDriverException
*/
public function rollback()
{
if (!mysqli_rollback($this->connection)) {
throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection));
$this->throwException($sql);
}
mysqli_autocommit($this->connection, TRUE);
}
@@ -353,6 +356,19 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
}
/**
* Converts database error to DibiDriverException
*
* @throws DibiDriverException
*/
protected function throwException($sql=NULL)
{
throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection), $sql);
}
/**
* Returns the connection resource
*