ArrayWrapper no longer returned from multiGetClass

multiGetClass uses FIND_IN_SET for ordering, which is pretty MariaDB specific.
This commit is contained in:
Mikael Nordfeldth 2014-06-02 00:13:54 +02:00
parent 3ef8322b03
commit 49188e826c

View File

@ -67,27 +67,35 @@ class Memcached_DataObject extends Safe_DataObject
* @param string $cls Class to fetch * @param string $cls Class to fetch
* @param string $keyCol name of column for key * @param string $keyCol name of column for key
* @param array $keyVals key values to fetch * @param array $keyVals key values to fetch
* @param boolean $skipNulls return only non-null results?
* *
* @return array Array of objects, in order * @return array Array of objects, in order
*/ */
static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls=true) static function multiGetClass($cls, $keyCol, array $keyVals)
{ {
$result = self::pivotGetClass($cls, $keyCol, $keyVals); $obj = new $cls;
$values = array_values($result); // php-compatible, for settype(), datatype
$colType = $obj->columnType($keyCol);
if ($skipNulls) { if (!in_array($colType, array('integer', 'int'))) {
$tmp = array(); // This is because I'm afraid to escape strings incorrectly
foreach ($values as $value) { // in the way we use them below in FIND_IN_SET for MariaDB
if (!empty($value)) { throw new ServerException('Cannot do multiGet on anything but integer columns');
$tmp[] = $value;
}
}
$values = $tmp;
} }
return new ArrayWrapper($values); $obj->whereAddIn($keyCol, $keyVals, $colType);
// Since we're inputting straight to a query: format and escape
foreach ($keyVals as $key=>$val) {
settype($val, $colType);
$keyVals[$key] = $obj->escape($val);
}
// FIND_IN_SET will make sure we keep the desired order
$obj->orderBy(sprintf("FIND_IN_SET(%s, '%s')", $keyCol, implode(',', $keyVals)));
$obj->find();
return $obj;
} }
/** /**