mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 05:37:39 +02:00
* fetchPairs improved
This commit is contained in:
@@ -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",
|
||||
);
|
||||
|
||||
|
||||
|
@@ -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());
|
||||
|
Reference in New Issue
Block a user