From c7dbc7134cb69177138004b75462ddc8671641ad Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 11 Jun 2007 00:25:48 +0000 Subject: [PATCH] * fetchPairs improved --- dibi/drivers/sqlite.php | 4 ++-- dibi/libs/resultset.php | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index 7dd0a136..3a903a4a 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -28,8 +28,8 @@ class DibiSqliteDriver extends DibiDriver $formats = array( 'TRUE' => "1", 'FALSE' => "0", - 'date' => "'Y-m-d'", - 'datetime' => "'Y-m-d H:i:s'", + 'date' => "U", + 'datetime' => "U", ); diff --git a/dibi/libs/resultset.php b/dibi/libs/resultset.php index 764f9098..59ec3cf6 100644 --- a/dibi/libs/resultset.php +++ b/dibi/libs/resultset.php @@ -248,16 +248,30 @@ abstract class DibiResult implements IteratorAggregate, Countable $rec = $this->fetch(); if (!$rec) return array(); // empty resultset + $arr = array(); + if ($value === NULL) { + if ($key !== NULL) return FALSE; // error + + // autodetect + if (count($rec) < 2) return FALSE; $tmp = array_keys($rec); $key = $tmp[0]; $value = $tmp[1]; + } else { - if (!array_key_exists($key, $rec)) return FALSE; if (!array_key_exists($value, $rec)) return FALSE; + + if ($key === NULL) { // autodetect + do { + $arr[] = $rec[$value]; + } while ($rec = $this->fetch()); + return $arr; + } + + if (!array_key_exists($key, $rec)) return FALSE; } - $arr = array(); do { $arr[ $rec[$key] ] = $rec[$value]; } while ($rec = $this->fetch());