From 53178717ad346edfd2825d135effd9af19b9d782 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 27 Mar 2007 23:38:09 +0000 Subject: [PATCH] * DibiPdoDriver bugs fixed --- dibi/#todo.txt | 1 + dibi/drivers/pdo.php | 30 ++++++++++++++---------------- examples/connect.php | 7 +++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/dibi/#todo.txt b/dibi/#todo.txt index 598808bb..798feb5d 100644 --- a/dibi/#todo.txt +++ b/dibi/#todo.txt @@ -1,2 +1,3 @@ +- PDO driver (current PDO driver is alpha version) - better examples - documentation diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index b3a723e5..fdb130ee 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -29,9 +29,7 @@ class DibiPdoDriver extends DibiDriver /** @var PDO */ private $conn; - private $affectedRows = FALSE, - - private $errorMsg; + private $affectedRows = FALSE; public $formats = array( @@ -67,16 +65,13 @@ class DibiPdoDriver extends DibiDriver { $this->affectedRows = FALSE; - $this->errorMsg = ''; + // TODO: or exec() ? $res = $this->conn->query($sql); if ($res === FALSE) return FALSE; - //$this->affectedRows = 0; - //if ($this->affectedRows < 0) $this->affectedRows = FALSE; - - if (is_resource($res)) - return new DibiSqliteResult($res); + if ($res instanceof PDOStatement) + return new DibiPdoResult($res); return TRUE; } @@ -125,15 +120,18 @@ class DibiPdoDriver extends DibiDriver public function escape($value, $appendQuotes = FALSE) { - return $appendQuotes - ? $this->conn->quote($value) - : FALSE; // error + if (!$appendQuotes) { + trigger_error('dibi: escaping without qoutes is not supported by PDO', E_USER_WARNING); + return NULL; + } + return $this->conn->quote($value); } public function quoteName($value) { - return FALSE; // error + // quoting is not supported by PDO + return $value; } @@ -150,8 +148,7 @@ class DibiPdoDriver extends DibiDriver */ public function applyLimit(&$sql, $limit, $offset = 0) { - if ($limit < 0 && $offset < 1) return; - $sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : ''); + trigger_error('Meta is not implemented.', E_USER_WARNING); } } // class DibiPdoDriver @@ -207,7 +204,8 @@ class DibiPdoResult extends DibiResult $count = $this->resource->columnCount(); $this->meta = $this->convert = array(); for ($index = 0; $index < $count; $index++) { - $meta = $this->resource->getColumnMeta($i); + $meta = $this->resource->getColumnMeta($index); + // TODO: $meta['type'] = dibi::FIELD_UNKNOWN; $name = $meta['name']; $this->meta[$name] = $meta; diff --git a/examples/connect.php b/examples/connect.php index 5f67dc64..afa92ea7 100644 --- a/examples/connect.php +++ b/examples/connect.php @@ -44,6 +44,13 @@ try { )); + // connects to PDO + dibi::connect(array( + 'driver' => 'pdo', + 'dsn' => 'sqlite2::memory:', + )); + + } catch (DibiException $e) { echo "DibiException:
", $e;