我们有一个这样的查询:
select C.* from stream_data AS sd
JOIN Conversations AS C
ON (C.conversationReferenceId = sd.stream_data_id AND smAccountId = ?)
WHERE sd.stream_id = ? LIMIT 1
我们使用 AdoDB 运行它。像这样:
$object = new Conversation();
$object->LoadFromRawQuery("select C.* from stream_data AS sd JOIN Conversations AS C ON (C.conversationReferenceId = sd.stream_data_id AND smAccountId = ?) WHERE sd.stream_id = ? LIMIT 1", array($socialmediaAccountId, $parentSourceId));
(注意:我们有一个自定义版本的 AdoDB,它在 AdoDB_RecordSet 类中有一个名为 LoadFromRawQuery 的方法,但是可以使用标准的 Execute() 方法调用来查看问题,所以我顺其自然。)
为了提高此查询的性能(基于我们的索引),我们添加了一个强制转换运算符:
#Query:
select C.* from stream_data AS sd
JOIN Conversations AS C
ON (C.conversationReferenceId = cast(sd.stream_data_id as char) collate utf8_unicode_ci AND smAccountId = ?)
WHERE sd.stream_id = ? LIMIT 1
#PHP
$object = new Conversation();
$object->LoadFromRawQuery("select C.* from stream_data AS sd JOIN Conversations AS C ON (C.conversationReferenceId = cast(sd.stream_data_id as char) collate utf8_unicode_ci AND smAccountId = ?) WHERE sd.stream_id = ? LIMIT 1", array($socialmediaAccountId, $parentSourceId));
这两个操作都在 Console 中工作,但在 AdoDB 中,第一个操作成功,而第二个操作失败。我们所有的表格都使用 UTF8 字符集。
帮助。