我正在尝试使用ZF2和MSSQL 2008来使用跟踪谓词。
$select = new Select();
$select -> from("MyTable");
$predicateIn = new Predicate\In('Bad Name', array(
"A",
"B",
"C"
));
$select -> where(array($predicateIn));
$resultSet = $this -> selectWith($select);
这是我得到的错误:
[Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near 'Bad'
打印生成的语句会显示以下内容,但无法找到解决方法。
SELECT "MyTable".* FROM "MyTable" WHERE "Bad" "Name" IN ('A', 'B', 'C')
转义任何其他引号,并使用[错误名称]导致相同的错误。 我很难过。
答案 0 :(得分:1)
我最终做了以下工作:
$select = new Select();
$select -> from("MyTable")
$platform = $this->adapter->getPlatform();
$filterList = array("A","B","C")
$predicateIn = $platform->quoteIdentifierChain(array('MyTable','Bad Name'));
$predicateIn .= " in (";
$predicateIn .= $platform->quoteValueList($filterList);
$predicateIn .= ")";
$select -> where(array($predicateIn));
$resultSet = $this -> selectWith($select);
我仍然想让Predicate \ In()工作。