从Zend Framework 2中生成的MYSQL中删除反转逗号

时间:2013-12-01 20:58:54

标签: mysql zend-framework2 code-generation

我一直在ZF2中创建一个MYSQL语句:

/**
 * get response by filter
 */
public function getResponsesByFilterArray($filter_array)
{
    $limit = 100;
    $rowset = $this->tableGateway->select(
            function (\Zend\Db\Sql\Select $select) use($where, $limit, $filter_array)
            {
                //$select->quantifier('DISTINCT');
                $select->join('question_responses', 'survey_responses.id = question_responses.response_id', array('value'));
                $select->where($where);
                foreach($filter_array as $filter_model)
                {

                    $select->where(array('question_id' => $filter_model->question_id));

                    switch($filter_model->comparison){
                        case $filter_model::$EQUALS:
                            $select->where->equalTo('value', $filter_model->value);
                            break;
                        case $filter_model::$GREATER_THAN:
                            $select->where->greaterThan('value', $filter_model->value);
                            break;
                        case $filter_model::$LESS_THAN:
                            $select->where->lessThan('value', $filter_model->value);
                            break;
                    }
                }
                $select->group('id');
                $select->limit($limit);

                $adapterPlatform = new \Zend\Db\Adapter\Platform\Mysql();
                echo $select->getSqlString($adapterPlatform);
            });

    return $rowset;
}

这会生成以下MySQL语句,除了一个非常重要的小点之外,它是完全正确的。

     SELECT `survey_responses`.*, `question_responses`.`value` AS `value` FROM `survey_responses` INNER JOIN `question_responses` ON `survey_responses`.`id` = `question_responses`.`response_id` WHERE `question_id` = '11' AND `value` > '900' GROUP BY `id` LIMIT 0,100

MySQL语句应该产生:

     SELECT `survey_responses`.*, `question_responses`.`value` AS `value` FROM `survey_responses` INNER JOIN `question_responses` ON `survey_responses`.`id` = `question_responses`.`response_id` WHERE `question_id` = '11' AND `value` > 900 GROUP BY `id` LIMIT 0,100

不同之处在于数字为900的倒置逗号。

如何从生成的MySQL语句中删除这些引号?

n.b这基于:

    $adapterPlatform = new \Zend\Db\Adapter\Platform\Mysql();
    echo $select->getSqlString($adapterPlatform);

虽然我认为这并不总能生成正确的MySQL字符串,但它是我唯一要做的事情,

提前致谢,

ABOR

1 个答案:

答案 0 :(得分:2)

只需将其转换为整数:

$select->where->greaterThan('value', (int)$filter_model->value);