示例#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);
 }
示例#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;
 }
示例#3
0
文件: In.php 项目: TuxBoy/Demo-saf
 /**
  * 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;
 }
示例#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 . '))';
 }
示例#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();
     }
 }
示例#6
0
文件: Range.php 项目: TuxBoy/Demo-saf
 /**
  * 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) . ')';
 }
示例#7
0
 /**
  * @return Link
  */
 public function getSqlLink()
 {
     return $this->where_builder->getSqlLink();
 }