Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Using sql functions in columns and predicates #2696

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

Using sql functions in columns and predicates #2696

ghost opened this issue Oct 7, 2012 · 6 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Oct 7, 2012

    $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
Copy link
Author

ghost commented Oct 8, 2012

Solves this with this.
#2687

@ralphschindler
Copy link
Member

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

@ghost ghost assigned ralphschindler Oct 9, 2012
@ghost
Copy link
Author

ghost commented Oct 9, 2012

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
Copy link
Author

ghost commented Oct 9, 2012

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
Copy link
Contributor

@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
Copy link
Author

ghost commented Aug 23, 2013

Thanks.

@ghost ghost closed this as completed Aug 23, 2013
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants