I trying to return an sql query with the code below. For some reason the boolean values I'm trying to filter by ('ShowOnHomePage' and 'Published') are throwing the following syntax error due to the question mark placeholder.
You have an error in your SQL syntax; check the manual that corresponds to >your MySQL server version for the right syntax to use near '?) AND ("DummyContentOne"."ShowOnHomePage" = ?)) "DummyContentOne" UNION ALL (S' at line 5
public function getSiteContent() {
if($this->_contentList!=false) {
return $this->_contentList;
}
$request = (Controller::has_curr() ? Controller::curr()->getRequest() : null);
$start = round(($request ? intval($request->getVar('start')) : 0));
$DummyContentOne = DummyContentOne::get()->filter('Published', true)->filter('ShowOnHomePage', true)->dataQuery()->query()->setOrderBy(null);
$DummyContentTwo = DummyContentTwo::get()->filter('Published', true)->filter('ShowOnHomePage', true)->dataQuery()->query()->setOrderBy(null);
$this->fixQueryColumns($DummyContentOne, $DummyContentTwo);
$db = DB::query(
'SELECT * '.
'FROM ('.$DummyContentOne->sql().') "DummyContentOne" '.
'UNION ALL ('.$DummyContentTwo->sql().') '.
'ORDER BY "Date" DESC, "Created" DESC '.
'LIMIT '.$this->config()->item_count.' OFFSET '.$start
);
// Merge into an array list
$list = new ArrayList();
foreach($db as $row) {
$className=$row['ClassName'];
$list->push(new $className($row, false, DataModel::inst()));
}
// Calculate the total number of items
$totalItems = $DummyContentOne->count() + $DummyContentTwo->count();
// Convert to a paginated list
$pagedList=ActionPaginatedList::create($list, $this->Link('more-content'), $request)
->setPageLength($this->config()->item_count)
->setPageStart($start)
->setTotalItems($totalItems)
->setLimitItems(false);
return $pagedList;
}
...
private function fixQueryColumns() {
$queries = func_get_args();
$columns = array();
// Debug::show($queries);
// Get all of the columns from each query
foreach($queries as $query) {
$columns = array_merge($columns, array_keys($query->getSelect()));
}
...
Any ideas what would cause this?
I'm using SS3.2
Thanks