Ejemplo n.º 1
0
 /**
  * Build SQL tables list, based on calculated joins for where array properties paths
  *
  * @return string
  */
 public function build()
 {
     $tables = BQ . Dao::current()->storeNameOf($this->class_name) . BQ . SP . 't0';
     foreach ($this->joins->getJoins() as $join) {
         if ($join) {
             $tables .= $join->toSql();
         }
     }
     return $tables;
 }
Ejemplo n.º 2
0
 /**
  * Build columns list for an object, in order to instantiate this object when read
  *
  * @param $path string
  * @param $join Join
  * @param $first_property boolean
  * @return string
  */
 private function buildObjectColumns($path, Join $join, &$first_property)
 {
     $sql_columns = '';
     if ($this->expand_objects) {
         foreach ($this->joins->getProperties($path) as $property) {
             $column_name = Sql\Builder::buildColumnName($property);
             if ($column_name) {
                 if ($first_property) {
                     $first_property = false;
                 } else {
                     $sql_columns .= ', ';
                 }
                 $sql_columns .= $join->foreign_alias . DOT . BQ . $column_name . BQ . ($this->append || !$this->resolve_aliases ? '' : ' AS ' . BQ . $path . ':' . $property->name . BQ);
             }
         }
         if ($first_property) {
             $first_property = false;
         } else {
             $sql_columns .= ', ';
         }
         $sql_columns .= $join->foreign_alias . '.id' . ($this->append || !$this->resolve_aliases ? '' : ' AS ' . BQ . $path . ':id' . BQ);
     } else {
         if ($first_property) {
             $first_property = false;
         } else {
             $sql_columns .= ', ';
         }
         $sql_columns .= $join->foreign_alias . '.id' . ($this->resolve_aliases ? ' AS ' . BQ . $path . BQ : '');
     }
     return $sql_columns;
 }
Ejemplo n.º 3
0
 /**
  * Build SQL WHERE section for given path and value
  *
  * @param $path        string|integer Property path starting by a root class property (may be a numeric key, or a structure keyword)
  * @param $value       mixed May be a value, or a structured array of multiple where clauses
  * @param $clause      string For multiple where clauses, tell if they are linked with 'OR' or 'AND'
  * @return string
  */
 private function buildPath($path, $value, $clause)
 {
     if ($value instanceof Func\Where) {
         $this->joins->add($path);
         list($master_path, $foreign_column) = Builder::splitPropertyPath($path);
         if ($foreign_column == 'id') {
             $prefix = '';
         } else {
             $properties = $this->joins->getProperties($master_path);
             $property = isset($properties[$foreign_column]) ? $properties[$foreign_column] : null;
             $id_links = [Link_Annotation::OBJECT, Link_Annotation::COLLECTION, Link_Annotation::MAP];
             $prefix = $property ? in_array($property->getAnnotation('link')->value, $id_links) ? 'id_' : '' : '';
         }
         return $value->toSql($this, $path, $prefix);
     } elseif ($value instanceof Date_Time) {
         // TODO a class annotation (@business? @string?) could help choose
         $value = $value->toISO(false);
     }
     switch (gettype($value)) {
         case 'NULL':
             return '';
         case 'array':
             return $this->buildArray($path, $value, $clause);
         case 'object':
             return $this->buildObject($path, $value);
         default:
             return $this->buildValue($path, $value);
     }
 }
Ejemplo n.º 4
0
 public function testSimple()
 {
     $this->assume('simple properties (Order::number)', Joins::newInstance(Order::class)->addMultiple(['date', 'number'])->getJoins(), ['date' => null, 'number' => null]);
 }