SilverStripe SQL布尔值语法错误

时间:2016-02-05 16:43:15

标签: php mysql sql content-management-system silverstripe

我尝试使用下面的代码返回sql查询。出于某种原因,我试图过滤的布尔值('ShowOnHomePage'和'Published')由于问号占位符而引发以下语法错误。

  

您的SQL语法有错误;查看与>你的MySQL服务器版本相对应的手册,以便在'?)附近使用正确的语法AND(“DummyContentOne”。“ShowOnHomePage”=?))“DummyContentOne”UNION ALL(S'在第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()));
    }
...

任何想法会导致什么?

我正在使用SS3.2

由于

0 个答案:

没有答案