/** * @return \NilPortugues\Sql\QueryBuilder\Syntax\Column * * @throws QueryException */ public function getColumns() { if (\is_null($this->select->getTable())) { throw new QueryException('No table specified for the Select instance'); } return SyntaxFactory::createColumns($this->columns, $this->select->getTable()); }
/** * @test */ public function itShouldBeCloneableWithoutKeepingReferences() { $query1 = new Select('user'); $query2 = clone $query1; $query2->setTable('users'); $this->assertFalse($query1->getTable() == $query2->getTable()); }
/** * @param Select $select * @param string $selfColumn * @param string $refColumn * * @return Select */ public function addJoin(Select $select, $selfColumn, $refColumn) { $select->isJoin(true); $table = $select->getTable()->getName(); if (!isset($this->joins[$table])) { $newColumn = array($selfColumn); $select->joinCondition()->equals($refColumn, SyntaxFactory::createColumn($newColumn, $this->select->getTable())); $this->joins[$table] = $select; } return $this->joins[$table]; }
/** * @param Select $select * @param string[] $parts * * @return $this */ public function writeSelectFrom(Select $select, array &$parts) { $parts = \array_merge($parts, ['FROM ' . $this->writer->writeTableWithAlias($select->getTable())]); return $this; }
/** * @param Select $select * * @return string */ public function writeJoin(Select $select) { if (null === $this->whereWriter) { $this->whereWriter = WriterFactory::createWhereWriter($this, $this->placeholderWriter); } $sql = $select->getJoinType() ? "{$select->getJoinType()} " : ''; $sql .= 'JOIN '; $sql .= $this->writeTableWithAlias($select->getTable()); $sql .= ' ON '; $sql .= $this->whereWriter->writeWhere($select->getJoinCondition()); return $sql; }