We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5811
    • 1,717 Posts

    I got an error condition with the following andCondition:
            $c->andCondition(array("( `dvdProducts`.`studio` REGEXP 'Warner Bros' )");

    And it’s ok with:
            $c->andCondition(array("( `dvdProducts`.`studio` = 'Warner Bros' )");

    Is there any reason for this ?

    Under PhpStorm I reach the following code block:
        public function isConditionalClause($string) {
            $matched= false;
            if (is_string($string)) {
                foreach ($this->_operators as $operator) {
                    if (strpos(strtoupper($string), $operator) !== false) {
                        $matched= true;
                        break;
                    }
                }
            }
            return $matched;
        }


    REGEXP doesn’t appear in the allowed list of operators inside the isConditionalClause function

    • I think there may be a bug filed for this in the xpdo project; can you do a quick search and if not add a ticket at http://bugs.modx.com/projects/xpdo/issues? In the meantime, you should be able to do the following, which is much better from a query abstraction perspective anyway:

      <?php
      $c->where(array('dvdProducts.studio:REGEXP' => 'Warner Bros'));
        • 5811
        • 1,717 Posts

        can you do a quick search and if not add a ticket at http://bugs.modx.com/projects/xpdo/issues? In the meantime
        Ok, I will do my best.

        is there anywhere an exhaustive list of examples on how should be set up these conditions ? I read this page. If it is obvious for most of them (=, >, <, ...), how are implemented :

        BETWEEN : like this ? $c->where(array(’name:BETWEEN’ => ’vmin,vmax’));
        NOT IN : $c->where(array(’name:NOT IN’ => ’v1,v2,v3,...,vn’));

        COALESCE ? $c->where(array(’name:COALESCE’ => ’v1,v2,v3,...,vn’));

        INTERVAL ?
        LEAST ? GREATEST ?

        Are the name of operator case sensitive ?
        Thanks.
        • Though xPDO has support for IN and NOT IN operators when binding values like this, it does not currently handle BETWEEN, nor does it support COALESCE() or other SQL-standard or engine-specific functions. When writing these types of conditions, just write them as a string for now, i.e.

          <?php
          $c->where(array(
              "{$modx->escape('name')} BETWEEN {$x} AND {$y}",
          ));
          
            • 5811
            • 1,717 Posts
            Thanks for the information.
            Regarding, REGEXP, this request has been logged as a feature (I just looked for bugs).
            As mike, I think that this operator will be a great value.