From d12895102f86e5299610405f916fe4a2df902bb9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 10 Jun 2008 01:09:23 +0000 Subject: [PATCH] - new DibiTable constructor - moved "tricky clone" from DibiConnection::query to IDibiDriver::query --- dibi/drivers/mssql.php | 4 ++-- dibi/drivers/mysql.php | 4 ++-- dibi/drivers/mysqli.php | 4 ++-- dibi/drivers/odbc.php | 4 ++-- dibi/drivers/oracle.php | 4 ++-- dibi/drivers/pdo.php | 6 +++--- dibi/drivers/postgre.php | 4 ++-- dibi/drivers/sqlite.php | 4 ++-- dibi/libs/DibiConnection.php | 4 +++- dibi/libs/DibiTable.php | 15 ++++----------- dibi/libs/interfaces.php | 2 +- readme.txt | 2 +- 12 files changed, 26 insertions(+), 31 deletions(-) diff --git a/dibi/drivers/mssql.php b/dibi/drivers/mssql.php index ad2b8173..033e61fb 100644 --- a/dibi/drivers/mssql.php +++ b/dibi/drivers/mssql.php @@ -109,7 +109,7 @@ class DibiMsSqlDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) @@ -120,7 +120,7 @@ class DibiMsSqlDriver extends /*Nette::*/Object implements IDibiDriver throw new DibiDriverException('Query error', 0, $sql); } - return is_resource($this->resultset); + return is_resource($this->resultset) ? clone $this : NULL; } diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php index 95cb7349..d0ae5cc8 100644 --- a/dibi/drivers/mysql.php +++ b/dibi/drivers/mysql.php @@ -158,7 +158,7 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) @@ -173,7 +173,7 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver $this->throwException($sql); } - return is_resource($this->resultset); + return is_resource($this->resultset) ? clone $this : NULL; } diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php index 0eba59bf..f6dd4b26 100644 --- a/dibi/drivers/mysqli.php +++ b/dibi/drivers/mysqli.php @@ -142,7 +142,7 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) @@ -153,7 +153,7 @@ class DibiMySqliDriver extends /*Nette::*/Object implements IDibiDriver $this->throwException($sql); } - return is_object($this->resultset); + return is_object($this->resultset) ? clone $this : NULL; } diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index 1a6060ba..aa294441 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -115,7 +115,7 @@ class DibiOdbcDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) @@ -126,7 +126,7 @@ class DibiOdbcDriver extends /*Nette::*/Object implements IDibiDriver $this->throwException($sql); } - return is_resource($this->resultset); + return is_resource($this->resultset) ? clone $this : NULL; } diff --git a/dibi/drivers/oracle.php b/dibi/drivers/oracle.php index f81b3f4b..f23ce409 100644 --- a/dibi/drivers/oracle.php +++ b/dibi/drivers/oracle.php @@ -108,7 +108,7 @@ class DibiOracleDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) @@ -125,7 +125,7 @@ class DibiOracleDriver extends /*Nette::*/Object implements IDibiDriver $this->throwException($sql); } - return is_resource($this->resultset); + return is_resource($this->resultset) ? clone $this : NULL; } diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index c1cef5df..e95f75c6 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -118,7 +118,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ public function query($sql) @@ -135,7 +135,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver $this->throwException($sql); } - return FALSE; + return NULL; } else { $this->resultset = $this->connection->query($sql); @@ -145,7 +145,7 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver $this->throwException($sql); } - return TRUE; + return clone $this; } } diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index 45998196..c6d955be 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -136,7 +136,7 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver * * @param string SQL statement. * @param bool update affected rows? - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ 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); } - return is_resource($this->resultset) && pg_num_fields($this->resultset); + return is_resource($this->resultset) && pg_num_fields($this->resultset) ? clone $this : NULL; } diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index 0f9d99e0..5f5aa9ce 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -122,7 +122,7 @@ class DibiSqliteDriver extends /*Nette::*/Object implements IDibiDriver * Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ 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); } - return is_resource($this->resultset); + return is_resource($this->resultset) ? clone $this : NULL; } diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index 38debd26..1321ab66 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -279,7 +279,9 @@ class DibiConnection extends /*Nette::*/Object $time = -microtime(TRUE); 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); dibi::$elapsedTime = $time; diff --git a/dibi/libs/DibiTable.php b/dibi/libs/DibiTable.php index 328e075e..eaee3fcd 100644 --- a/dibi/libs/DibiTable.php +++ b/dibi/libs/DibiTable.php @@ -37,9 +37,6 @@ abstract class DibiTable extends /*Nette::*/Object /** @var DibiConnection */ private $connection; - /** @var array */ - private $options; - /** @var string table name */ protected $name; @@ -53,20 +50,16 @@ abstract class DibiTable extends /*Nette::*/Object protected $blankRow = array(); + /** * Table constructor. - * @param array + * @param DibiConnection * @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(); - - if ($this->connection === NULL) { - $this->connection = dibi::getConnection(); - } } diff --git a/dibi/libs/interfaces.php b/dibi/libs/interfaces.php index 616d7dce..fea0cefa 100644 --- a/dibi/libs/interfaces.php +++ b/dibi/libs/interfaces.php @@ -89,7 +89,7 @@ interface IDibiDriver * Internal: Executes the SQL query. * * @param string SQL statement. - * @return bool have resultset? + * @return IDibiDriver|NULL * @throws DibiDriverException */ function query($sql); diff --git a/readme.txt b/readme.txt index 2d9acfbd..d394c60f 100644 --- a/readme.txt +++ b/readme.txt @@ -38,4 +38,4 @@ whitespaces are removed. ----- For more information, visit the author's weblog (in czech language): -http://www.latrine.cz +http://phpfashion.com