Using sql functions in columns and predicates #2696

Closed
ghost opened this Issue Oct 7, 2012 · 6 comments

2 participants

@ghost
    $select = $sql->select();
    $select->columns(array('COUNT(*)'));
    $operator = new \Zend\Db\Sql\Predicate\Operator();
    $operator->setLeft('name')->setRight("CONCAT({$db->getPlatform()->quoteValue('string1')}, 'string2')")->setRightType($operator::TYPE_LITERAL);

    $select->where(array(
        $operator,
        new \Zend\Db\Sql\Predicate\PredicateSet(array(
            new \Zend\Db\Sql\Predicate\Like('title', '%string%'),
        )),
    ));

Is there no way to achieve this? Or something to allow literal string and I'll take care the quoting and escaping?

@ghost

Solves this with this.
#2687

@ralphschindler
Zend Framework member

So, since #2687 was merged, this works now, right?

@ghost

It works with predicate right values and select->columns. But it is not consistent, It doesn't prepended the identifiers with the table name, like it does when you provide literal string in select->columns. Also I can't use the expression as a left operand in operator predicate, Haven't tried with other predicates yet.

@ghost

Another issue I think, I'm not sure if it is done by design. The expression 3rd parameter is always an array, I'm lazy and I don't want to always type an array if I just have one parameter or all parameters have the same type.

@ThaDafinser

@coudvanrm about the 3rd expression parameter: this is solved, see here:
https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Sql/Expression.php#L39

About the orginal problem: is there still something that needs to be done?

@ghost

Thanks.

@ghost ghost closed this Aug 23, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment