Returns an expression using the specified operator.
public buildClause ( string $lhs, string $op, string $rhs, boolean $bind = false, array $params = [] ) : string | array | ||
$lhs | string | The column or expression to test. |
$op | string | The operator. |
$rhs | string | The comparison value. |
$bind | boolean | If true, the method returns the query and a list of values suitable for binding as an array. |
$params | array | Any additional parameters for the operator. |
Résultat | string | array | The SQL test fragment, or an array containing the query and a list of values if $bind is true. |
/** * Returns an expression using the specified operator. * * @param string $lhs The column or expression to test. * @param string $op The operator. * @param string $rhs The comparison value. * @param boolean $bind If true, the method returns the query and a list * of values suitable for binding as an array. * @param array $params Any additional parameters for the operator. * * @return string|array The SQL test fragment, or an array containing the * query and a list of values if $bind is true. */ public function buildClause($lhs, $op, $rhs, $bind = false, $params = array()) { $lhs = $this->_escapePrepare($lhs); switch ($op) { case '|': if ($bind) { return array($lhs . ' + ? - BITAND(' . $lhs . ', ?)', array((int) $rhs, (int) $rhs)); } return $lhs . ' + ' . (int) $rhs . ' - BITAND(' . $lhs . ', ' . (int) $rhs . ')'; case '&': if ($bind) { return array('BITAND(' . $lhs . ', ?)', array((int) $rhs)); } return 'BITAND(' . $lhs . ', ' . (int) $rhs . ')'; } return parent::buildClause($lhs, $op, $rhs, $bind, $params); }
/** * Returns an expression using the specified operator. * * @param string $lhs The column or expression to test. * @param string $op The operator. * @param string $rhs The comparison value. * @param boolean $bind If true, the method returns the query and a list * of values suitable for binding as an array. * @param array $params Any additional parameters for the operator. * * @return string|array The SQL test fragment, or an array containing the * query and a list of values if $bind is true. */ public function buildClause($lhs, $op, $rhs, $bind = false, $params = array()) { $lhs = $this->_escapePrepare($lhs); switch ($op) { case '|': case '&': /* Only PgSQL 7.3+ understands SQL99 'SIMILAR TO'; use ~ for * greater backwards compatibility. */ $query = 'CASE WHEN CAST(%s AS VARCHAR) ~ \'^-?[0-9]+$\' THEN (CAST(%s AS INTEGER) %s %s) ELSE 0 END'; if ($bind) { return array(sprintf($query, $lhs, $lhs, $op, '?'), array((int) $rhs)); } else { return sprintf($query, $lhs, $lhs, $op, (int) $rhs); } case 'LIKE': $query = '%s ILIKE %s'; if ($bind) { if (empty($params['begin'])) { return array(sprintf($query, $lhs, '?'), array('%' . $rhs . '%')); } return array(sprintf('(' . $query . ' OR ' . $query . ')', $lhs, '?', $lhs, '?'), array($rhs . '%', '% ' . $rhs . '%')); } if (empty($params['begin'])) { return sprintf($query, $lhs, $this->_escapePrepare($this->quote('%' . $rhs . '%'))); } return sprintf('(' . $query . ' OR ' . $query . ')', $lhs, $this->_escapePrepare($this->quote($rhs . '%')), $lhs, $this->_escapePrepare($this->quote('% ' . $rhs . '%'))); } return parent::buildClause($lhs, $op, $rhs, $bind, $params); }
/** * Returns an expression using the specified operator. * * @param string $lhs The column or expression to test. * @param string $op The operator. * @param string $rhs The comparison value. * @param boolean $bind If true, the method returns the query and a list * of values suitable for binding as an array. * @param array $params Any additional parameters for the operator. * * @return string|array The SQL test fragment, or an array containing the * query and a list of values if $bind is true. */ public function buildClause($lhs, $op, $rhs, $bind = false, $params = array()) { switch ($op) { case '~': if ($bind) { return array($lhs . ' REGEXP ?', array($rhs)); } else { return $lhs . ' REGEXP ' . $rhs; } } return parent::buildClause($lhs, $op, $rhs, $bind, $params); }