Ejemplo n.º 1
0
 /**
  * Adds a table to the statement
  * @param zibo\library\database\manipulation\expression\TableExpression $table
  * @return null;
  */
 public function addTable(TableExpression $table)
 {
     $alias = $table->getAlias();
     if ($alias) {
         $this->tables[$alias] = $table;
     } else {
         $this->tables[$table->getName()] = $table;
     }
 }
 public function testConstructWithAlias()
 {
     $table = new TableExpression('table', 'alias');
     $this->assertEquals('table', $table->getName());
     $this->assertEquals('alias', $table->getAlias());
 }
 /**
  * Create the SQL of the given table for a FROM expression
  * @param zibo\library\database\manipulation\expression\TableExpression $table
  * @return string SQL representation of the table
  */
 protected function parseTableExpressionForFrom(TableExpression $table)
 {
     $tableName = $this->connection->quoteIdentifier($table->getName());
     $tableAlias = $table->getAlias();
     if ($tableAlias != null) {
         $tableName .= ' AS ' . $this->connection->quoteIdentifier($tableAlias);
     }
     return $tableName;
 }
Ejemplo n.º 4
0
 /**
  * Processes a field of a relation model
  * @param string $name Name of the field
  * @param zibo\library\database\manipulation\expression\TableExpression $table Table expression for the field
  * @param boolean $inCondition Flag to see whether the provided expression is used in a condition or not
  * @return zibo\library\database\manipulation\expression\FieldExpression
  */
 private function processRelationFieldExpression($name, TableExpression $table, $inCondition)
 {
     $tableName = $table->getName();
     try {
         $field = $this->meta->getField($tableName);
     } catch (OrmException $e) {
         if (!isset($this->tables[$tableName])) {
             throw new OrmParseException('Table ' . $tableName . ' is not added to the query');
         }
         return new FieldExpression($name, $this->tables[$tableName], $tableName . self::ALIAS_SEPARATOR . $name);
     }
     $isRelationField = $field instanceof RelationField;
     if ($isRelationField) {
         $this->addFieldJoin($field);
     }
     $relationModel = $this->meta->getRelationModel($tableName);
     $relationField = $relationModel->getMeta()->getField($name);
     if ($relationField->isLocalized()) {
         $table = $this->meta->getRelationLocalizedTable($tableName);
         if ($inCondition && $isRelationField) {
             $joinCondition = $this->createLocalizeCondition($this->meta->getRelationTable($tableName), $table);
             $join = new JoinExpression(JoinExpression::TYPE_LEFT, $table, $joinCondition);
             $this->addConditionJoin($join);
         }
     } else {
         $table = new TableExpression($relationModel->getName(), $tableName);
     }
     return new FieldExpression($name, $table, $tableName . self::ALIAS_SEPARATOR . $name);
 }