mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Revert "Optimised keyedColumn() and map() for MySQLQuery"
This commit is contained in:
parent
8b8ea1aab0
commit
5aa52f1343
@ -60,40 +60,4 @@ class MySQLQuery extends Query
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing all values in the leftmost column, where the keys are the
|
||||
* same as the values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keyedColumn()
|
||||
{
|
||||
$column = [];
|
||||
if (is_object($this->handle)) {
|
||||
foreach ($this->handle->fetch_all(MYSQLI_ASSOC) as $record) {
|
||||
$val = $record[key($record)];
|
||||
$column[$val] = $val;
|
||||
}
|
||||
}
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map from the first column to the second column.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
$column = [];
|
||||
if (is_object($this->handle)) {
|
||||
foreach ($this->handle->fetch_all(MYSQLI_ASSOC) as $record) {
|
||||
$key = reset($record);
|
||||
$val = next($record);
|
||||
$column[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $column;
|
||||
}
|
||||
}
|
||||
|
@ -336,24 +336,6 @@ class DataQueryTest extends SapphireTest
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
public function testMap()
|
||||
{
|
||||
$fixtures = DataQueryTest\ObjectC::get();
|
||||
$expected = array();
|
||||
foreach ($fixtures as $fixture) {
|
||||
$expected[$fixture->ID] = $fixture->Title;
|
||||
$fixture->destroy();
|
||||
}
|
||||
$result = DB::query("SELECT \"ID\", \"Title\" FROM \"DataQueryTest_C\"")->map();
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testKeyedColumn()
|
||||
{
|
||||
$result = DB::query("SELECT \"Title\" FROM \"DataQueryTest_C\"")->keyedColumn();
|
||||
$this->assertEquals(['First' => 'First', 'Second' => 'Second', 'Last' => 'Last'], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that getFinalisedQuery can include all tables
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user