mirror of
https://github.com/dg/dibi.git
synced 2025-02-22 18:02:25 +01:00
- removed DibiPostgreDriver workaround (there is no bug in pg_affected_rows)
- added IDibiConnection::isConnected()
This commit is contained in:
parent
b27b0193f1
commit
a8acce6d59
@ -199,7 +199,7 @@ class dibi
|
||||
*/
|
||||
public static function isConnected()
|
||||
{
|
||||
return (bool) self::$connection;
|
||||
return (self::$connection !== NULL) && self::$connection->isConnected();
|
||||
}
|
||||
|
||||
|
||||
@ -214,7 +214,7 @@ class dibi
|
||||
public static function getConnection($name = NULL)
|
||||
{
|
||||
if ($name === NULL) {
|
||||
if (!self::$connection) {
|
||||
if (self::$connection === NULL) {
|
||||
throw new DibiException('Dibi is not connected to database.');
|
||||
}
|
||||
|
||||
|
@ -77,16 +77,16 @@ class DibiMsSqlDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
DibiConnection::alias($config, 'host');
|
||||
|
||||
if (empty($config['persistent'])) {
|
||||
$this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE);
|
||||
$this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE); // intentionally @
|
||||
} else {
|
||||
$this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']);
|
||||
$this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']); // intentionally @
|
||||
}
|
||||
|
||||
if (!is_resource($this->connection)) {
|
||||
throw new DibiDriverException("Can't connect to DB.");
|
||||
}
|
||||
|
||||
if (isset($config['database']) && !@mssql_select_db($config['database'], $this->connection)) {
|
||||
if (isset($config['database']) && !@mssql_select_db($config['database'], $this->connection)) { // intentionally @
|
||||
throw new DibiDriverException("Can't select DB '$config[database]'.");
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ class DibiMsSqlDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
$this->resultset = @mssql_query($sql, $this->connection);
|
||||
$this->resultset = @mssql_query($sql, $this->connection); // intentionally @
|
||||
|
||||
if ($this->resultset === FALSE) {
|
||||
throw new DibiDriverException('Query error', 0, $sql);
|
||||
|
@ -110,9 +110,9 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
}
|
||||
|
||||
if (empty($config['persistent'])) {
|
||||
$this->connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['options']);
|
||||
$this->connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['options']); // intentionally @
|
||||
} else {
|
||||
$this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['options']);
|
||||
$this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['options']); // intentionally @
|
||||
}
|
||||
|
||||
if (!is_resource($this->connection)) {
|
||||
@ -123,18 +123,18 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
$ok = FALSE;
|
||||
if (function_exists('mysql_set_charset')) {
|
||||
// affects the character set used by mysql_real_escape_string() (was added in MySQL 5.0.7 and PHP 5.2.3)
|
||||
$ok = @mysql_set_charset($config['charset'], $this->connection);
|
||||
$ok = @mysql_set_charset($config['charset'], $this->connection); // intentionally @
|
||||
}
|
||||
if (!$ok) $ok = @mysql_query("SET NAMES '$config[charset]'", $this->connection);
|
||||
if (!$ok) $ok = @mysql_query("SET NAMES '$config[charset]'", $this->connection); // intentionally @
|
||||
if (!$ok) $this->throwException();
|
||||
}
|
||||
|
||||
if (isset($config['database'])) {
|
||||
@mysql_select_db($config['database'], $this->connection) or $this->throwException();
|
||||
@mysql_select_db($config['database'], $this->connection) or $this->throwException(); // intentionally @
|
||||
}
|
||||
|
||||
if (isset($config['sqlmode'])) {
|
||||
if (!@mysql_query("SET sql_mode='$config[sqlmode]'", $this->connection)) $this->throwException();
|
||||
if (!@mysql_query("SET sql_mode='$config[sqlmode]'", $this->connection)) $this->throwException(); // intentionally @
|
||||
}
|
||||
|
||||
$this->buffered = empty($config['unbuffered']);
|
||||
@ -164,9 +164,9 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
public function query($sql)
|
||||
{
|
||||
if ($this->buffered) {
|
||||
$this->resultset = @mysql_query($sql, $this->connection);
|
||||
$this->resultset = @mysql_query($sql, $this->connection); // intentionally @
|
||||
} else {
|
||||
$this->resultset = @mysql_unbuffered_query($sql, $this->connection);
|
||||
$this->resultset = @mysql_unbuffered_query($sql, $this->connection); // intentionally @
|
||||
}
|
||||
|
||||
if (mysql_errno($this->connection)) {
|
||||
|
@ -101,7 +101,7 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
}
|
||||
|
||||
$this->connection = mysqli_init();
|
||||
@mysqli_real_connect($this->connection, $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['options']);
|
||||
@mysqli_real_connect($this->connection, $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['options']); // intentionally @
|
||||
|
||||
if ($errno = mysqli_connect_errno()) {
|
||||
throw new DibiDriverException(mysqli_connect_error(), $errno);
|
||||
@ -111,14 +111,14 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
$ok = FALSE;
|
||||
if (version_compare(PHP_VERSION , '5.1.5', '>=')) {
|
||||
// affects the character set used by mysql_real_escape_string() (was added in MySQL 5.0.7 and PHP 5.0.5, fixed in PHP 5.1.5)
|
||||
$ok = @mysqli_set_charset($this->connection, $config['charset']);
|
||||
$ok = @mysqli_set_charset($this->connection, $config['charset']); // intentionally @
|
||||
}
|
||||
if (!$ok) $ok = @mysqli_query($this->connection, "SET NAMES '$config[charset]'");
|
||||
if (!$ok) $ok = @mysqli_query($this->connection, "SET NAMES '$config[charset]'"); // intentionally @
|
||||
if (!$ok) $this->throwException();
|
||||
}
|
||||
|
||||
if (isset($config['sqlmode'])) {
|
||||
if (!@mysqli_query($this->connection, "SET sql_mode='$config[sqlmode]'")) $this->throwException();
|
||||
if (!@mysqli_query($this->connection, "SET sql_mode='$config[sqlmode]'")) $this->throwException(); // intentionally @
|
||||
}
|
||||
|
||||
$this->buffered = empty($config['unbuffered']);
|
||||
@ -147,7 +147,7 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
$this->resultset = @mysqli_query($this->connection, $sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT);
|
||||
$this->resultset = @mysqli_query($this->connection, $sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // intentionally @
|
||||
|
||||
if (mysqli_errno($this->connection)) {
|
||||
$this->throwException($sql);
|
||||
|
@ -87,9 +87,9 @@ class DibiOdbcDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
if (!isset($config['dsn'])) $config['dsn'] = ini_get('odbc.default_db');
|
||||
|
||||
if (empty($config['persistent'])) {
|
||||
$this->connection = @odbc_connect($config['dsn'], $config['username'], $config['password']);
|
||||
$this->connection = @odbc_connect($config['dsn'], $config['username'], $config['password']); // intentionally @
|
||||
} else {
|
||||
$this->connection = @odbc_pconnect($config['dsn'], $config['username'], $config['password']);
|
||||
$this->connection = @odbc_pconnect($config['dsn'], $config['username'], $config['password']); // intentionally @
|
||||
}
|
||||
|
||||
if (!is_resource($this->connection)) {
|
||||
@ -120,7 +120,7 @@ class DibiOdbcDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
$this->resultset = @odbc_exec($this->connection, $sql);
|
||||
$this->resultset = @odbc_exec($this->connection, $sql); // intentionally @
|
||||
|
||||
if ($this->resultset === FALSE) {
|
||||
$this->throwException($sql);
|
||||
|
@ -82,7 +82,7 @@ class DibiOracleDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
DibiConnection::alias($config, 'database', 'db');
|
||||
DibiConnection::alias($config, 'charset');
|
||||
|
||||
$this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']);
|
||||
$this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']); // intentionally @
|
||||
|
||||
if (!$this->connection) {
|
||||
$err = oci_error();
|
||||
|
@ -316,7 +316,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
$meta = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
// items 'name' and 'table' are required
|
||||
$info = @$this->resultset->getColumnsMeta($i);
|
||||
$info = @$this->resultset->getColumnsMeta($i); // intentionally @
|
||||
if ($info === FALSE) {
|
||||
throw new DibiDriverException('Driver does not support meta data.');
|
||||
}
|
||||
|
@ -58,13 +58,6 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
private $escMethod = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Affected rows.
|
||||
* @var int|FALSE
|
||||
*/
|
||||
private $affectedRows = FALSE;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @throws DibiException
|
||||
@ -148,16 +141,13 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
$this->resultset = @pg_query($this->connection, $sql);
|
||||
$this->resultset = @pg_query($this->connection, $sql); // intentionally @
|
||||
|
||||
if ($this->resultset === FALSE) {
|
||||
$this->affectedRows = FALSE;
|
||||
throw new DibiDriverException(pg_last_error($this->connection), 0, $sql);
|
||||
}
|
||||
|
||||
$this->affectedRows = pg_affected_rows($this->resultset); // retrieve immediately due PHP bug
|
||||
|
||||
return is_resource($this->resultset);
|
||||
return is_resource($this->resultset) && pg_num_fields($this->resultset);
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +159,7 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
*/
|
||||
public function affectedRows()
|
||||
{
|
||||
return $this->affectedRows;
|
||||
return pg_affected_rows($this->resultset);
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,9 +92,9 @@ class DibiSqliteDriver extends /*Nette::*/Object implements IDibiDriver
|
||||
|
||||
$errorMsg = '';
|
||||
if (empty($config['persistent'])) {
|
||||
$this->connection = @sqlite_open($config['database'], 0666, $errorMsg);
|
||||
$this->connection = @sqlite_open($config['database'], 0666, $errorMsg); // intentionally @
|
||||
} else {
|
||||
$this->connection = @sqlite_popen($config['database'], 0666, $errorMsg);
|
||||
$this->connection = @sqlite_popen($config['database'], 0666, $errorMsg); // intentionally @
|
||||
}
|
||||
|
||||
if (!$this->connection) {
|
||||
|
@ -90,7 +90,7 @@ class DibiConnection extends /*Nette::*/Object
|
||||
}
|
||||
|
||||
if (isset($config['result:objects'])) {
|
||||
// normalize
|
||||
// normalize
|
||||
$val = $config['result:objects'];
|
||||
$config['result:objects'] = is_string($val) && !is_numeric($val) ? $val : (bool) $val;
|
||||
}
|
||||
@ -154,6 +154,18 @@ class DibiConnection extends /*Nette::*/Object
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE when connection was established.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
final public function isConnected()
|
||||
{
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns configuration variable. If no $key is passed, returns the entire array.
|
||||
*
|
||||
@ -411,9 +423,9 @@ class DibiConnection extends /*Nette::*/Object
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
@set_time_limit(0);
|
||||
@set_time_limit(0); // intentionally @
|
||||
|
||||
$handle = @fopen($file, 'r');
|
||||
$handle = @fopen($file, 'r'); // intentionally @
|
||||
if (!$handle) {
|
||||
throw new FileNotFoundException("Cannot open file '$file'.");
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@$this->free();
|
||||
@$this->free(); // intentionally @
|
||||
}
|
||||
|
||||
|
||||
|
@ -131,9 +131,9 @@ final class DibiTranslator extends /*Nette::*/Object
|
||||
)/xs',
|
||||
*/ // note: this can change $this->args & $this->cursor & ...
|
||||
. preg_replace_callback('/(?=`|\[|\'|"|%)(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|%([a-zA-Z]{1,4})(?![a-zA-Z]))/s',
|
||||
array($this, 'cb'),
|
||||
substr($arg, $toSkip)
|
||||
);
|
||||
array($this, 'cb'),
|
||||
substr($arg, $toSkip)
|
||||
);
|
||||
|
||||
}
|
||||
continue;
|
||||
@ -302,9 +302,9 @@ final class DibiTranslator extends /*Nette::*/Object
|
||||
} else {
|
||||
return substr($value, 0, $toSkip)
|
||||
. preg_replace_callback('/(?=`|\[|\'|")(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"(\'|"))/s',
|
||||
array($this, 'cb'),
|
||||
substr($value, $toSkip)
|
||||
);
|
||||
array($this, 'cb'),
|
||||
substr($value, $toSkip)
|
||||
);
|
||||
}
|
||||
|
||||
case 'a':
|
||||
|
@ -85,6 +85,15 @@ interface IDibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE when connection was established.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isConnected();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user