1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

- DibiPostgreDriver: added support for "schema"

- DibiTable::fetch($conditions) (experimental)
- DibiConnection no longer invokes autoloading
This commit is contained in:
David Grudl
2008-02-14 02:02:27 +00:00
parent 8da9e778a6
commit 2f9704bca2
4 changed files with 18 additions and 7 deletions

View File

@@ -23,8 +23,8 @@
/** /**
* Check PHP configuration. * Check PHP configuration.
*/ */
if (version_compare(PHP_VERSION , '5.1.0', '<')) { if (version_compare(PHP_VERSION, '5.1.0', '<')) {
throw new LogicException('dibi needs PHP 5.1.0 or newer.'); throw new Exception('dibi needs PHP 5.1.0 or newer.');
} }

View File

@@ -26,6 +26,7 @@
* - 'string' - or use connection string * - 'string' - or use connection string
* - 'persistent' - try to find a persistent link? * - 'persistent' - try to find a persistent link?
* - 'charset' - character encoding to set * - 'charset' - character encoding to set
* - 'schema' - the schema search path
* - 'lazy' - if TRUE, connection will be established only when required * - 'lazy' - if TRUE, connection will be established only when required
* *
* @author David Grudl * @author David Grudl
@@ -105,6 +106,10 @@ class DibiPostgreDriver extends NObject implements IDibiDriver
DibiDriverException::restore(); DibiDriverException::restore();
} }
if (isset($config['schema'])) {
$this->query('SET search_path TO ' . $config['schema']);
}
$this->escMethod = version_compare(PHP_VERSION , '5.2.0', '>='); $this->escMethod = version_compare(PHP_VERSION , '5.2.0', '>=');
} }

View File

@@ -74,10 +74,10 @@ class DibiConnection extends NObject
$driver = preg_replace('#[^a-z0-9_]#', '_', $config['driver']); $driver = preg_replace('#[^a-z0-9_]#', '_', $config['driver']);
$class = "Dibi" . $driver . "Driver"; $class = "Dibi" . $driver . "Driver";
if (!class_exists($class)) { if (!class_exists($class, FALSE)) {
include_once __FILE__ . "/../../drivers/$driver.php"; 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'."); throw new DibiException("Unable to create instance of dibi driver class '$class'.");
} }
} }

View File

@@ -225,14 +225,20 @@ abstract class DibiTable extends NObject
/** /**
* Fetches single row. * Fetches single row.
* @param scalar primary key value * @param scalar|array primary key value
* @return array|object row * @return array|object row
*/ */
public function fetch($what) public function fetch($conditions)
{ {
if (is_array($conditions)) {
return $this->complete($this->connection->query( return $this->complete($this->connection->query(
'SELECT * FROM %n', $this->name, 'SELECT * FROM %n', $this->name,
'WHERE %n', $this->primary, '=' . $this->primaryModifier, $what 'WHERE %and', $conditions
))->fetch();
}
return $this->complete($this->connection->query(
'SELECT * FROM %n', $this->name,
'WHERE %n=' . $this->primaryModifier, $this->primary, $conditions
))->fetch(); ))->fetch();
} }