mirror of
https://github.com/dg/dibi.git
synced 2025-08-16 02:54:25 +02:00
added DibiDriver::disconnect()
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiMsSqlDriver extends DibiDriver
|
||||
final class DibiMsSqlDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -61,7 +61,7 @@ class DibiMsSqlDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('mssql')) {
|
||||
throw new DibiException("PHP extension 'mssql' is not loaded");
|
||||
@@ -83,17 +83,28 @@ class DibiMsSqlDriver extends DibiDriver
|
||||
throw new DibiDatabaseException("Can't select DB '$config[database]'");
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doDisconnect()
|
||||
{
|
||||
mssql_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
@@ -104,7 +115,7 @@ class DibiMsSqlDriver extends DibiDriver
|
||||
throw new DibiDatabaseException('Query error', 0, $sql);
|
||||
}
|
||||
|
||||
return is_resource($res) ? new DibiMSSqlResult($res) : TRUE;
|
||||
return is_resource($res) ? new DibiMSSqlResult($res) : NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +269,7 @@ class DibiMsSqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiMSSqlResult extends DibiResult
|
||||
final class DibiMSSqlResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiMySqlDriver extends DibiDriver
|
||||
final class DibiMySqlDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -70,7 +70,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('mysql')) {
|
||||
throw new DibiException("PHP extension 'mysql' is not loaded");
|
||||
@@ -116,17 +116,28 @@ class DibiMySqlDriver extends DibiDriver
|
||||
throw new DibiDatabaseException(mysql_error($connection), mysql_errno($connection));
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doDisconnect()
|
||||
{
|
||||
mysql_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
@@ -138,7 +149,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
throw new DibiDatabaseException(mysql_error($connection), $errno, $sql);
|
||||
}
|
||||
|
||||
return is_resource($res) ? new DibiMySqlResult($res) : TRUE;
|
||||
return is_resource($res) ? new DibiMySqlResult($res) : NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +302,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiMySqlResult extends DibiResult
|
||||
final class DibiMySqlResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiMySqliDriver extends DibiDriver
|
||||
final class DibiMySqliDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -71,7 +71,7 @@ class DibiMySqliDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('mysqli')) {
|
||||
throw new DibiException("PHP extension 'mysqli' is not loaded");
|
||||
@@ -89,17 +89,28 @@ class DibiMySqliDriver extends DibiDriver
|
||||
mysqli_query($connection, "SET NAMES '" . $config['charset'] . "'");
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doDisconnect()
|
||||
{
|
||||
mysqli_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
@@ -111,7 +122,7 @@ class DibiMySqliDriver extends DibiDriver
|
||||
throw new DibiDatabaseException(mysqli_error($connection), $errno, $sql);
|
||||
}
|
||||
|
||||
return is_object($res) ? new DibiMySqliResult($res) : TRUE;
|
||||
return is_object($res) ? new DibiMySqliResult($res) : NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -275,7 +286,7 @@ class DibiMySqliDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiMySqliResult extends DibiResult
|
||||
final class DibiMySqliResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiOdbcDriver extends DibiDriver
|
||||
final class DibiOdbcDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -74,7 +74,7 @@ class DibiOdbcDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('odbc')) {
|
||||
throw new DibiException("PHP extension 'odbc' is not loaded");
|
||||
@@ -92,28 +92,19 @@ class DibiOdbcDriver extends DibiDriver
|
||||
throw new DibiDatabaseException(odbc_errormsg(), odbc_error());
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes the SQL query
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @throws DibiException
|
||||
* @return void
|
||||
*/
|
||||
public function nativeQuery($sql)
|
||||
protected function doDisconnect()
|
||||
{
|
||||
$this->affectedRows = FALSE;
|
||||
$res = parent::nativeQuery($sql);
|
||||
if ($res instanceof DibiResult) {
|
||||
$this->affectedRows = odbc_num_rows($res->getResource());
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
}
|
||||
return $res;
|
||||
odbc_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
@@ -122,11 +113,12 @@ class DibiOdbcDriver extends DibiDriver
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
{
|
||||
$this->affectedRows = FALSE;
|
||||
$connection = $this->getConnection();
|
||||
$res = @odbc_exec($connection, $sql);
|
||||
|
||||
@@ -134,7 +126,11 @@ class DibiOdbcDriver extends DibiDriver
|
||||
throw new DibiDatabaseException(odbc_errormsg($connection), odbc_error($connection), $sql);
|
||||
}
|
||||
|
||||
return is_resource($res) ? new DibiOdbcResult($res) : TRUE;
|
||||
if (is_resource($res)) {
|
||||
$this->affectedRows = odbc_num_rows($res);
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
return new DibiOdbcResult($res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +291,7 @@ class DibiOdbcDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiOdbcResult extends DibiResult
|
||||
final class DibiOdbcResult extends DibiResult
|
||||
{
|
||||
private $row = 0;
|
||||
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiOracleDriver extends DibiDriver
|
||||
final class DibiOracleDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -65,7 +65,7 @@ class DibiOracleDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('oci8')) {
|
||||
throw new DibiException("PHP extension 'oci8' is not loaded");
|
||||
@@ -79,17 +79,28 @@ class DibiOracleDriver extends DibiDriver
|
||||
throw new DibiDatabaseException($err['message'], $err['code']);
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doDisconnect()
|
||||
{
|
||||
oci_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
@@ -260,7 +271,7 @@ class DibiOracleDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiOracleResult extends DibiResult
|
||||
final class DibiOracleResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiPdoDriver extends DibiDriver
|
||||
final class DibiPdoDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -61,7 +61,7 @@ class DibiPdoDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('pdo')) {
|
||||
throw new DibiException("PHP extension 'pdo' is not loaded");
|
||||
@@ -70,24 +70,33 @@ class DibiPdoDriver extends DibiDriver
|
||||
$config = $this->getConfig();
|
||||
$connection = new PDO($config['dsn'], $config['username'], $config['password']);
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doDisconnect()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
{
|
||||
$res = $this->getConnection()->query($sql);
|
||||
return $res instanceof PDOStatement ? new DibiPdoResult($res) : TRUE;
|
||||
return $res instanceof PDOStatement ? new DibiPdoResult($res) : NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +244,7 @@ class DibiPdoDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiPdoResult extends DibiResult
|
||||
final class DibiPdoResult extends DibiResult
|
||||
{
|
||||
private $row = 0;
|
||||
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiPostgreDriver extends DibiDriver
|
||||
final class DibiPostgreDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -67,7 +67,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
throw new DibiException("PHP extension 'pgsql' is not loaded");
|
||||
@@ -101,28 +101,19 @@ class DibiPostgreDriver extends DibiDriver
|
||||
// don't handle this error...
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes the SQL query
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @throws DibiException
|
||||
* @return void
|
||||
*/
|
||||
public function nativeQuery($sql)
|
||||
protected function doDisconnect()
|
||||
{
|
||||
$this->affectedRows = FALSE;
|
||||
$res = parent::nativeQuery($sql);
|
||||
if ($res instanceof DibiResult) {
|
||||
$this->affectedRows = pg_affected_rows($res->getResource());
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
}
|
||||
return $res;
|
||||
pg_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
@@ -131,10 +122,11 @@ class DibiPostgreDriver extends DibiDriver
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @param bool update affected rows?
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
protected function doQuery($sql, $silent = FALSE)
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
$res = @pg_query($connection, $sql);
|
||||
@@ -143,7 +135,13 @@ class DibiPostgreDriver extends DibiDriver
|
||||
throw new DibiDatabaseException(pg_last_error($connection), 0, $sql);
|
||||
}
|
||||
|
||||
return is_resource($res) ? new DibiPostgreResult($res) : TRUE;
|
||||
if (is_resource($res)) {
|
||||
if (!$silent) {
|
||||
$this->affectedRows = pg_affected_rows($res);
|
||||
if ($this->affectedRows < 0) $this->affectedRows = FALSE;
|
||||
}
|
||||
return new DibiPostgreResult($res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,9 +167,9 @@ class DibiPostgreDriver extends DibiDriver
|
||||
{
|
||||
if ($sequence === NULL) {
|
||||
// PostgreSQL 8.1 is needed
|
||||
$res = $this->doQuery("SELECT LASTVAL() AS seq");
|
||||
$res = $this->doQuery("SELECT LASTVAL() AS seq", TRUE);
|
||||
} else {
|
||||
$res = $this->doQuery("SELECT CURRVAL('$sequence') AS seq");
|
||||
$res = $this->doQuery("SELECT CURRVAL('$sequence') AS seq", TRUE);
|
||||
}
|
||||
|
||||
if (is_resource($res)) {
|
||||
@@ -191,7 +189,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
*/
|
||||
public function begin()
|
||||
{
|
||||
$this->doQuery('BEGIN');
|
||||
$this->doQuery('BEGIN', TRUE);
|
||||
dibi::notify('begin', $this);
|
||||
}
|
||||
|
||||
@@ -203,7 +201,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
$this->doQuery('COMMIT');
|
||||
$this->doQuery('COMMIT', TRUE);
|
||||
dibi::notify('commit', $this);
|
||||
}
|
||||
|
||||
@@ -215,7 +213,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
*/
|
||||
public function rollback()
|
||||
{
|
||||
$this->doQuery('ROLLBACK');
|
||||
$this->doQuery('ROLLBACK', TRUE);
|
||||
dibi::notify('rollback', $this);
|
||||
}
|
||||
|
||||
@@ -306,7 +304,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiPostgreResult extends DibiResult
|
||||
final class DibiPostgreResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
class DibiSqliteDriver extends DibiDriver
|
||||
final class DibiSqliteDriver extends DibiDriver
|
||||
{
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
@@ -60,7 +60,7 @@ class DibiSqliteDriver extends DibiDriver
|
||||
* @throws DibiException
|
||||
* @return resource
|
||||
*/
|
||||
protected function connect()
|
||||
protected function doConnect()
|
||||
{
|
||||
if (!extension_loaded('sqlite')) {
|
||||
throw new DibiException("PHP extension 'sqlite' is not loaded");
|
||||
@@ -79,29 +79,41 @@ class DibiSqliteDriver extends DibiDriver
|
||||
throw new DibiDatabaseException($errorMsg);
|
||||
}
|
||||
|
||||
dibi::notify('connected', $this);
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doDisconnect()
|
||||
{
|
||||
sqlite_close($this->getConnection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query
|
||||
*
|
||||
* @param string SQL statement.
|
||||
* @return DibiResult|TRUE Result set object
|
||||
* @return DibiResult Result set object
|
||||
* @throws DibiDatabaseException
|
||||
*/
|
||||
protected function doQuery($sql)
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
$res = @sqlite_query($connection, $sql, SQLITE_ASSOC);
|
||||
$errorMsg = NULL;
|
||||
$res = @sqlite_query($connection, $sql, SQLITE_ASSOC, $errorMsg);
|
||||
|
||||
if ($errno = sqlite_last_error($connection)) {
|
||||
throw new DibiDatabaseException(sqlite_error_string($errno), $errno, $sql);
|
||||
if ($errorMsg !== NULL) {
|
||||
throw new DibiDatabaseException($errorMsg, sqlite_last_error($connection), $sql);
|
||||
}
|
||||
|
||||
return is_resource($res) ? new DibiSqliteResult($res) : TRUE;
|
||||
return is_resource($res) ? new DibiSqliteResult($res) : NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +261,7 @@ class DibiSqliteDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
class DibiSqliteResult extends DibiResult
|
||||
final class DibiSqliteResult extends DibiResult
|
||||
{
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user