Esempio n. 1
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string column name prefix
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     $column = $builder->buildColumn($property_path, $prefix);
     if (is_null($this->than_value)) {
         switch ($this->sign) {
             case self::EQUAL:
                 return $column . ' IS NULL';
             case self::NOT_EQUAL:
                 return $column . ' IS NOT NULL';
         }
     }
     return $column . SP . $this->sign . SP . Value::escape($this->than_value, strpos($this->sign, 'LIKE') !== false);
 }
Esempio n. 2
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     $joins = $builder->getJoins();
     // sub-query
     $class_name = $joins->getStartingClassName();
     $properties = $this->properties + [$property_path => Func::max()];
     $sub_builder = new Builder\Select($class_name, $properties, null, $builder->getSqlLink(), [Dao::groupBy($this->properties)]);
     // join
     $join = new Subquery($sub_builder);
     $joins->addJoin($join);
     // where
     $where = '';
     foreach (array_merge($this->properties, [$property_path]) as $property) {
         $where .= ' AND ' . $join->foreign_alias . DOT . BQ . rLastParse($property, DOT, 1, true) . BQ . ' = ' . $builder->buildColumn($property, $prefix);
     }
     $join->where = substr($where, 5);
     return null;
 }
Esempio n. 3
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string column name prefix
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     $sql = '';
     if ($this->values) {
         $sql = $builder->buildColumn($property_path, $prefix) . ' IN (';
         $first = true;
         foreach ($this->values as $value) {
             if ($first) {
                 $first = false;
             } else {
                 $sql .= ', ';
             }
             $sql .= Value::escape($value);
         }
         $sql .= ')';
     }
     return $sql;
 }
Esempio n. 4
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string column name prefix
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     $column = $builder->buildColumn($property_path, $prefix);
     $value = Value::escape($this->value);
     return $column . ' = LEFT(' . $value . ', LENGTH(' . $column . '))';
 }
Esempio n. 5
0
 /**
  * Apply a restriction to the builder
  *
  * @param $builder     Select
  * @param $class_name  string
  * @param $restriction string|array a restriction callback
  */
 private function applyRestriction(Select $builder, $class_name, $restriction)
 {
     if ($restriction == self::CURRENT) {
         $restriction = [$class_name, 'current'];
     }
     $where_array = call_user_func_array($restriction, [$class_name, $builder->getJoins()]);
     if ($where_array) {
         $where_builder = new Where($builder->getJoins()->getStartingClassName(), $where_array, $builder->getSqlLink(), $builder->getJoins());
         $this->current_restrictions[] = $where_builder->build();
     }
 }
Esempio n. 6
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string column name prefix
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     return '(' . $builder->buildColumn($property_path, $prefix) . ' BETWEEN ' . Value::escape($this->from) . ' AND ' . Value::escape($this->to) . ')';
 }
Esempio n. 7
0
 /**
  * @return Link
  */
 public function getSqlLink()
 {
     return $this->where_builder->getSqlLink();
 }