/** * Get a SQL option array for the given query and preprocessed query object at given id. * * @param Query $query * @param integer $rootId * * @return array */ private function getSQLOptions(Query $query, $rootId) { $result = array('LIMIT' => $query->getLimit() + 5, 'OFFSET' => $query->getOffset()); // Build ORDER BY options using discovered sorting fields. if ($this->engineOptions->get('smwgQSortingSupport')) { $qobj = $this->querySegments[$rootId]; foreach ($this->sortKeys as $propkey => $order) { if (!is_string($propkey)) { throw new RuntimeException("Expected a string value as sortkey"); } // #835 // SELECT DISTINCT and ORDER BY RANDOM causes an issue for postgres // Disable RANDOM support for postgres if ($this->store->getConnection()->getType() === 'postgres') { $this->engineOptions->set('smwgQRandSortingSupport', false); } if ($order != 'RANDOM' && array_key_exists($propkey, $qobj->sortfields)) { // Field was successfully added. $result['ORDER BY'] = (array_key_exists('ORDER BY', $result) ? $result['ORDER BY'] . ', ' : '') . $qobj->sortfields[$propkey] . " {$order} "; } elseif ($order == 'RANDOM' && $this->engineOptions->get('smwgQRandSortingSupport')) { $result['ORDER BY'] = (array_key_exists('ORDER BY', $result) ? $result['ORDER BY'] . ', ' : '') . ' RAND() '; } } } return $result; }
public function testAddOption() { $instance = new EngineOptions(); $this->assertFalse($instance->has('Foo')); $instance->set('Foo', 42); $this->assertEquals(42, $instance->get('Foo')); }