1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-04 21:28:02 +02:00

* fetchPairs improved

This commit is contained in:
David Grudl
2007-06-11 00:25:48 +00:00
parent e33689a5a1
commit c7dbc7134c
2 changed files with 18 additions and 4 deletions

View File

@@ -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",
);

View File

@@ -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());