我想跳过N' N'我拉数据时的行。使用原始SQL我可以使用WHERE 'id' %%%u=0
完成此操作,其中' u'是我的间隔。我可以使用Criteria对象完成此操作吗?我试过这个:$c->getNewCriterion(GaugeDataPeer::ID%$interval, 0, Criteria::EQUAL);
但无济于事。
这是在Symfony 1.4上。不确定Propel版本是什么。
这是我尝试重新创建的完整查询:
$query = sprintf("SELECT *
FROM `processed_gauge_data`
WHERE `id` %%%u=0 AND `processed_gauge_data`.`gauge_id` IN (%s) AND `processed_gauge_data`.`stamp` >= '%s' AND `processed_gauge_data`.`stamp` <= '%s';",
$interval,
implode(',', $gauge),
mysql_real_escape_string(date('Y-m-d H:i:s', $start)),
mysql_real_escape_string(date('Y-m-d H:i:s', $end))
);
答案 0 :(得分:1)
只需使用->where
->where('ProcessedGaugeData.Id %%%u = 0')
并更好地使用ActiveQuery:http://propelorm.org/blog/2010/08/03/refactoring-to-propel-1-5-from-peer-classes-to-query-classes.html
答案 1 :(得分:-1)
找到解决方案!
我的老代码:
$c = new Criteria();
$c->add(GaugeDataPeer::GAUGE_ID, $this->getId(), Criteria::EQUAL);
$start_c = $c->getNewCriterion(GaugeDataPeer::STAMP, $dates['start']->format('Y-m-d H:i:s'), Criteria::GREATER_EQUAL);
$end_c = $c->getNewCriterion(GaugeDataPeer::STAMP, $dates['end']->format('Y-m-d H:i:s'), Criteria::LESS_EQUAL);
$start_c->addAnd($end_c);
$c->add($start_c);
$c->addAscendingOrderByColumn(GaugeDataPeer::STAMP);
$data_array = GaugeDataPeer::doSelect($c);
我的新代码
$query = sprintf("SELECT *
FROM `gauge_data`
WHERE `id` %%%u=0 AND `gauge_data`.`gauge_id` IN (%s) AND `gauge_data`.`stamp` >= '".$dates['start']->format('Y-m-d H:i:s')."' AND `gauge_data`.`stamp` <= '".$dates['end']->format('Y-m-d H:i:s')."';",
$interval,
implode(',', array($this->getId()))
);
$conn = Propel::getConnection();
$st = $conn->prepare($query);
$st->execute();
$data_array = $st->fetchAll(PDO::FETCH_CLASS, GaugeData);