From 2f9704bca25f2c80c39f8e1ac64f600c9a0cb8d3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 14 Feb 2008 02:02:27 +0000 Subject: [PATCH] - DibiPostgreDriver: added support for "schema" - DibiTable::fetch($conditions) (experimental) - DibiConnection no longer invokes autoloading --- dibi/dibi.php | 4 ++-- dibi/drivers/postgre.php | 5 +++++ dibi/libs/DibiConnection.php | 4 ++-- dibi/libs/DibiTable.php | 12 +++++++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dibi/dibi.php b/dibi/dibi.php index e8271c7c..060198c3 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -23,8 +23,8 @@ /** * Check PHP configuration. */ -if (version_compare(PHP_VERSION , '5.1.0', '<')) { - throw new LogicException('dibi needs PHP 5.1.0 or newer.'); +if (version_compare(PHP_VERSION, '5.1.0', '<')) { + throw new Exception('dibi needs PHP 5.1.0 or newer.'); } diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index 22f1316f..5bc75dcb 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -26,6 +26,7 @@ * - 'string' - or use connection string * - 'persistent' - try to find a persistent link? * - 'charset' - character encoding to set + * - 'schema' - the schema search path * - 'lazy' - if TRUE, connection will be established only when required * * @author David Grudl @@ -105,6 +106,10 @@ class DibiPostgreDriver extends NObject implements IDibiDriver DibiDriverException::restore(); } + if (isset($config['schema'])) { + $this->query('SET search_path TO ' . $config['schema']); + } + $this->escMethod = version_compare(PHP_VERSION , '5.2.0', '>='); } diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index 3c614ea0..0a56bdbb 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -74,10 +74,10 @@ class DibiConnection extends NObject $driver = preg_replace('#[^a-z0-9_]#', '_', $config['driver']); $class = "Dibi" . $driver . "Driver"; - if (!class_exists($class)) { + if (!class_exists($class, FALSE)) { include_once __FILE__ . "/../../drivers/$driver.php"; - if (!class_exists($class)) { + if (!class_exists($class, FALSE)) { throw new DibiException("Unable to create instance of dibi driver class '$class'."); } } diff --git a/dibi/libs/DibiTable.php b/dibi/libs/DibiTable.php index e45ffd9e..e59e5496 100644 --- a/dibi/libs/DibiTable.php +++ b/dibi/libs/DibiTable.php @@ -225,14 +225,20 @@ abstract class DibiTable extends NObject /** * Fetches single row. - * @param scalar primary key value + * @param scalar|array primary key value * @return array|object row */ - public function fetch($what) + public function fetch($conditions) { + if (is_array($conditions)) { + return $this->complete($this->connection->query( + 'SELECT * FROM %n', $this->name, + 'WHERE %and', $conditions + ))->fetch(); + } return $this->complete($this->connection->query( 'SELECT * FROM %n', $this->name, - 'WHERE %n', $this->primary, '=' . $this->primaryModifier, $what + 'WHERE %n=' . $this->primaryModifier, $this->primary, $conditions ))->fetch(); }