1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-07 14:46:50 +02:00

- all drivers accepts injected connection resource

- DibiFluent: fixed identifier substitution
This commit is contained in:
David Grudl
2009-01-17 19:27:40 +00:00
parent 47d1180aee
commit 5ecfaf7ab1
10 changed files with 108 additions and 71 deletions

View File

@@ -29,6 +29,7 @@
* - 'persistent' - try to find a persistent link?
* - 'database' - the database name to select
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -67,7 +68,9 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver
DibiConnection::alias($config, 'password', 'pass');
DibiConnection::alias($config, 'host', 'hostname');
if (empty($config['persistent'])) {
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} elseif (empty($config['persistent'])) {
$this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE); // intentionally @
} else {
$this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']); // intentionally @

View File

@@ -27,6 +27,7 @@
* - 'options' - connection info array {@link http://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx}
* - 'lazy' - if TRUE, connection will be established only when required
* - 'charset' - character encoding to set (default is UTF-8)
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -66,7 +67,9 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver
{
DibiConnection::alias($config, 'host', 'hostname');
if (isset($config['options'])) {
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} elseif (isset($config['options'])) {
$this->connection = sqlsrv_connect($config['host'], $config['options']);
} else {
$this->connection = sqlsrv_connect($config['host']);

View File

@@ -35,6 +35,7 @@
* - 'options' - driver specific constants (MYSQL_*)
* - 'sqlmode' - see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -77,6 +78,10 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
DibiConnection::alias($config, 'host', 'hostname');
DibiConnection::alias($config, 'options');
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
// default values
if (!isset($config['username'])) $config['username'] = ini_get('mysql.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('mysql.default_password');
@@ -102,6 +107,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
} else {
$this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['options']); // intentionally @
}
}
if (!is_resource($this->connection)) {
throw new DibiDriverException(mysql_error(), mysql_errno());

View File

@@ -35,6 +35,7 @@
* - 'options' - driver specific constants (MYSQLI_*)
* - 'sqlmode' - see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -78,6 +79,10 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
DibiConnection::alias($config, 'options');
DibiConnection::alias($config, 'database');
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
// default values
if (!isset($config['username'])) $config['username'] = ini_get('mysqli.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('mysqli.default_pw');
@@ -100,6 +105,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
if ($errno = mysqli_connect_errno()) {
throw new DibiDriverException(mysqli_connect_error(), $errno);
}
}
if (isset($config['charset'])) {
$ok = FALSE;

View File

@@ -28,6 +28,7 @@
* - 'password' (or 'pass')
* - 'persistent' - try to find a persistent link?
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -68,6 +69,9 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver
DibiConnection::alias($config, 'username', 'user');
DibiConnection::alias($config, 'password', 'pass');
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
// default values
if (!isset($config['username'])) $config['username'] = ini_get('odbc.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('odbc.default_pw');
@@ -78,6 +82,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver
} else {
$this->connection = @odbc_pconnect($config['dsn'], $config['username'], $config['password']); // intentionally @
}
}
if (!is_resource($this->connection)) {
throw new DibiDriverException(odbc_errormsg() . ' ' . odbc_error());

View File

@@ -28,6 +28,7 @@
* - 'password' (or 'pass')
* - 'charset' - character encoding to set
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -70,7 +71,11 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
DibiConnection::alias($config, 'database', 'db');
DibiConnection::alias($config, 'charset');
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
$this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']); // intentionally @
}
if (!$this->connection) {
$err = oci_error();

View File

@@ -27,7 +27,7 @@
* - 'username' (or 'user')
* - 'password' (or 'pass')
* - 'options' - driver specific options array
* - 'pdo' - PDO object (optional)
* - 'resource' - PDO object (optional)
* - 'lazy' - if TRUE, connection will be established only when required
*
* @author David Grudl
@@ -69,11 +69,11 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
DibiConnection::alias($config, 'username', 'user');
DibiConnection::alias($config, 'password', 'pass');
DibiConnection::alias($config, 'dsn');
DibiConnection::alias($config, 'pdo');
DibiConnection::alias($config, 'resource', 'pdo');
DibiConnection::alias($config, 'options');
if ($config['pdo'] instanceof PDO) {
$this->connection = $config['pdo'];
if ($config['resource'] instanceof PDO) {
$this->connection = $config['resource'];
} else try {
$this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);

View File

@@ -29,6 +29,7 @@
* - 'charset' - character encoding to set
* - 'schema' - the schema search path
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -66,6 +67,10 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
*/
public function connect(array &$config)
{
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
if (isset($config['string'])) {
$string = $config['string'];
} else {
@@ -84,6 +89,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
if (DibiDriverException::catchError($msg)) {
throw new DibiDriverException($msg, 0);
}
}
if (!is_resource($this->connection)) {
throw new DibiDriverException('Connecting error.');

View File

@@ -31,6 +31,7 @@
* - 'formatDateTime' - how to format datetime in SQL (@see date)
* - 'dbcharset' - database character encoding (will be converted to 'charset')
* - 'charset' - character encoding to set (default is UTF-8)
* - 'resource' - connection resource (optional)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -79,7 +80,9 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
$this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
$errorMsg = '';
if (empty($config['persistent'])) {
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} elseif (empty($config['persistent'])) {
$this->connection = @sqlite_open($config['database'], 0666, $errorMsg); // intentionally @
} else {
$this->connection = @sqlite_popen($config['database'], 0666, $errorMsg); // intentionally @

View File

@@ -119,7 +119,7 @@ class DibiFluent extends DibiObject
if ($arg === TRUE) { // flag
$args = array();
} elseif (is_string($arg) && preg_match('#^[a-z][a-z0-9_.]*$#i', $arg)) { // identifier
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*$#i', $arg)) { // identifier
$args = array('%n', $arg);
} elseif ($arg instanceof self) {