简体   繁体   English

在Doctrine 1.2中使用Doctrine_Query的奇怪行为

[英]Strange behaviour with Doctrine_Query in Doctrine 1.2

I have a query that has multiple orWhere statements. 我有一个包含多个orWhere语句的查询。 The PHP code looks like this: PHP代码如下所示:

$firstDay = $params['datetimeForMonth']->format('Y-m-d');
$lastDay = $params['datetimeForMonth']->format('Y-m-t 23:59:59');
$whereStatement = "(s.level = ?
    AND s.idForLevel IN (?) 
    AND s.startDatetime BETWEEN '$firstDay' AND '$lastDay')";
$q = Doctrine_Query::create()
    ->from('Mmb_Model_Schedule s')
    ->where($whereStatement, ['prefecture', $this->id])
    ->orWhere($whereStatement, ['district', $districtIds])
    ->orWhere($whereStatement, ['municipality', $municipalityIds])
    ->orWhere($whereStatement, ['workplace',    $workplaceIds])
    ->orWhere($whereStatement, ['user', $userIds]);

The variables $districtIds, $municipalityIds, $workplaceIds, and $userIds are all defined ahead of time as comma separated values. 变量$ districtIds,$ municipalityIds,$ workplaceIds和$ userIds都提前定义为逗号分隔的值。

This query works just fine with every level except for the district ids. 该查询对每个级别(区域ID除外)都适用。 Any record with the level "district" will not be returned in the query. 查询中不会返回任何级别为“区”的记录。

What's really strange is that, if I don't use bound parameters but rather insert the following code, everything works fine: 真正奇怪的是,如果我不使用绑定参数,而是插入以下代码,则一切正常:

->orWhere("s.level = 'district' AND s.idForLevel IN ($districtIds) AND s.startDatetime BETWEEN '$firstDay' AND '$lastDay'")

What's even more infuriating is that even this query done all by itself as a single where statement (excluding all the others) also gives me nothing if I use bound parameters. 更令人气愤的是,如果我使用绑定参数,即使该查询本身作为单个where语句(不包括所有其他语句)单独完成,也不会给我任何帮助。

And as if that weren't enough, I even tried updating the table changing 'district' to 'prefDistrict', just in case the word 'district' was causing the problems. 似乎还不够,我什至尝试将表从“ district”更改为“ prefDistrict”,以防万一单词“ district”引起了问题。 Nothing changed. 没有改变。

Despite the fact that I'm inserting the EXACT SAME data as bound parameters as when entering them directly, the behaviour changes dramatically. 尽管我像直接输入时一样将EXACT SAME数据作为绑定参数插入,但行为却发生了巨大变化。 What on Earth is going on here? 这到底是怎么回事?

I want to say that there must be something in the values of the $districtIds var that is tripping up the query builder in Doctrine. 我想说的是, $districtIds var的值中一定有某些东西使Toctrine中的查询生成器崩溃。 Can you post a sample of what those values are? 您可以张贴这些值的样本吗?

Also, have you looked at the generated SQL that doctrine runs (either tailing an SQL log, or hooking into the preExecute event)? 另外,您是否看过了运行该理论的生成的SQL(拖尾SQL日志或挂接到preExecute事件)? I'd be curious to see the output of something like that. 我很好奇看到这样的输出。

(this should probably be a comment, but my reputation isn't high enough for that ;) ) (这可能是一条评论,但是我的声誉还不够高;))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM