mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 13:47:33 +02:00
- new DibiTable constructor
- moved "tricky clone" from DibiConnection::query to IDibiDriver::query
This commit is contained in:
@@ -109,7 +109,7 @@ class DibiMsSqlDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -120,7 +120,7 @@ class DibiMsSqlDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
throw new DibiDriverException('Query error', 0, $sql);
|
throw new DibiDriverException('Query error', 0, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_resource($this->resultset);
|
return is_resource($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -158,7 +158,7 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -173,7 +173,7 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
$this->throwException($sql);
|
$this->throwException($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_resource($this->resultset);
|
return is_resource($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -142,7 +142,7 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -153,7 +153,7 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
$this->throwException($sql);
|
$this->throwException($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_object($this->resultset);
|
return is_object($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -115,7 +115,7 @@ class DibiOdbcDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -126,7 +126,7 @@ class DibiOdbcDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
$this->throwException($sql);
|
$this->throwException($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_resource($this->resultset);
|
return is_resource($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -108,7 +108,7 @@ class DibiOracleDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -125,7 +125,7 @@ class DibiOracleDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
$this->throwException($sql);
|
$this->throwException($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_resource($this->resultset);
|
return is_resource($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -118,7 +118,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -135,7 +135,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
$this->throwException($sql);
|
$this->throwException($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->resultset = $this->connection->query($sql);
|
$this->resultset = $this->connection->query($sql);
|
||||||
@@ -145,7 +145,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
$this->throwException($sql);
|
$this->throwException($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return clone $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -136,7 +136,7 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @param bool update affected rows?
|
* @param bool update affected rows?
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -147,7 +147,7 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
throw new DibiDriverException(pg_last_error($this->connection), 0, $sql);
|
throw new DibiDriverException(pg_last_error($this->connection), 0, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_resource($this->resultset) && pg_num_fields($this->resultset);
|
return is_resource($this->resultset) && pg_num_fields($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ class DibiSqliteDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
@@ -137,7 +137,7 @@ class DibiSqliteDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
throw new DibiDriverException($msg, sqlite_last_error($this->connection), $sql);
|
throw new DibiDriverException($msg, sqlite_last_error($this->connection), $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_resource($this->resultset);
|
return is_resource($this->resultset) ? clone $this : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -279,7 +279,9 @@ class DibiConnection extends /*Nette::*/Object
|
|||||||
$time = -microtime(TRUE);
|
$time = -microtime(TRUE);
|
||||||
dibi::notify($this, 'beforeQuery', $sql);
|
dibi::notify($this, 'beforeQuery', $sql);
|
||||||
|
|
||||||
$res = $this->driver->query($sql) ? new DibiResult(clone $this->driver, $this->config) : NULL;
|
if ($res = $this->driver->query($sql)) { // intentionally =
|
||||||
|
$res = new DibiResult($res, $this->config);
|
||||||
|
}
|
||||||
|
|
||||||
$time += microtime(TRUE);
|
$time += microtime(TRUE);
|
||||||
dibi::$elapsedTime = $time;
|
dibi::$elapsedTime = $time;
|
||||||
|
@@ -37,9 +37,6 @@ abstract class DibiTable extends /*Nette::*/Object
|
|||||||
/** @var DibiConnection */
|
/** @var DibiConnection */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $options;
|
|
||||||
|
|
||||||
/** @var string table name */
|
/** @var string table name */
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
@@ -53,20 +50,16 @@ abstract class DibiTable extends /*Nette::*/Object
|
|||||||
protected $blankRow = array();
|
protected $blankRow = array();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table constructor.
|
* Table constructor.
|
||||||
* @param array
|
* @param DibiConnection
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(array $options = array())
|
public function __construct(DibiConnection $connection = NULL)
|
||||||
{
|
{
|
||||||
$this->options = $options;
|
$this->connection = $connection === NULL ? dibi::getConnection() : $connection;
|
||||||
|
|
||||||
$this->setup();
|
$this->setup();
|
||||||
|
|
||||||
if ($this->connection === NULL) {
|
|
||||||
$this->connection = dibi::getConnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -89,7 +89,7 @@ interface IDibiDriver
|
|||||||
* Internal: Executes the SQL query.
|
* Internal: Executes the SQL query.
|
||||||
*
|
*
|
||||||
* @param string SQL statement.
|
* @param string SQL statement.
|
||||||
* @return bool have resultset?
|
* @return IDibiDriver|NULL
|
||||||
* @throws DibiDriverException
|
* @throws DibiDriverException
|
||||||
*/
|
*/
|
||||||
function query($sql);
|
function query($sql);
|
||||||
|
@@ -38,4 +38,4 @@ whitespaces are removed.
|
|||||||
|
|
||||||
-----
|
-----
|
||||||
For more information, visit the author's weblog (in czech language):
|
For more information, visit the author's weblog (in czech language):
|
||||||
http://www.latrine.cz
|
http://phpfashion.com
|
||||||
|
Reference in New Issue
Block a user