예제 #1
0
 /**
  * Returns the SQL to check if a value is one in a set of
  * given values.
  *
  * in() accepts an arbitrary number of parameters. The first parameter
  * must always specify the value that should be matched against. Successive
  * parameters must contain a logical expression or an array with logical
  * expressions.  These expressions will be matched against the first
  * parameter.
  *
  * Example:
  * <code>
  * $q->select( '*' )->from( 'table' )
  *                  ->where( $q->expr->in( 'id', 1, 2, 3 ) );
  * </code>
  *
  * Oracle limits the number of values in a single IN() to 1000. This 
  * implementation creates a list of combined IN() expressions to bypass 
  * this limitation.
  *
  * @throws ezcQueryVariableParameterException if called with less than two
  *         parameters.
  * @throws ezcQueryInvalidParameterException if the 2nd parameter is an
  *         empty array.
  * @param string|array(string) values that will be matched against $column
  * @return string logical expression
  */
 public function in($column)
 {
     $args = func_get_args();
     if (count($args) < 2) {
         throw new ezcQueryVariableParameterException('in', count($args), 2);
     }
     if (is_array($args[1]) && count($args[1]) == 0) {
         throw new ezcQueryInvalidParameterException('in', 2, 'empty array', 'non-empty array');
     }
     $values = ezcQuerySelect::arrayFlatten(array_slice($args, 1));
     $values = $this->getIdentifiers($values);
     $column = $this->getIdentifier($column);
     if (count($values) == 0) {
         throw new ezcQueryVariableParameterException('in', count($args), 2);
     }
     if ($this->quoteValues) {
         foreach ($values as $key => $value) {
             switch (true) {
                 case is_int($value):
                 case is_float($value):
                 case $value instanceof ezcQuerySubSelect:
                     $values[$key] = (string) $value;
                     break;
                 default:
                     $values[$key] = $this->db->quote($value);
             }
         }
     }
     if (count($values) <= 1000) {
         return "{$column} IN ( " . join(', ', $values) . ' )';
     } else {
         $expression = '( ';
         do {
             $bunch = array_slice($values, 0, 1000);
             $values = array_slice($values, 1000);
             $expression .= "{$column} IN ( " . join(', ', $bunch) . ' ) OR ';
         } while (count($values) > 1000);
         $expression .= "{$column} IN ( " . join(', ', $values) . ' ) )';
         return $expression;
     }
 }
예제 #2
0
 /**
  * Returns a series of strings concatinated
  *
  * concat() accepts an arbitrary number of parameters. Each parameter
  * must contain an expression or an array with expressions.
  *
  * @param string|array(string) $... strings that will be concatinated.
  */
 public function concat()
 {
     $args = func_get_args();
     $cols = ezcQuerySelect::arrayFlatten($args);
     if (count($cols) < 1) {
         throw new ezcQueryVariableParameterException('concat', count($args), 1);
     }
     $cols = $this->getIdentifiers($cols);
     return "CONCAT( " . join(', ', $cols) . ' )';
 }