/** * @test */ public function getSQLDelegatesToConcreteQueryBuilder() { $this->concreteQueryBuilder->getSQL()->shouldBeCalled()->willReturn('UPDATE aTable SET pid = 7'); $this->concreteQueryBuilder->getType()->willReturn(2); // Update Type $this->subject->getSQL(); }
/** * Constructor. * * @param QueryBuilder $queryBuilder A DBAL query builder. * @param callable $countQueryBuilderModifier A callable to modifier the query builder to count. */ public function __construct(QueryBuilder $queryBuilder, $countQueryBuilderModifier) { if ($queryBuilder->getType() !== QueryBuilder::SELECT) { throw new InvalidArgumentException('Only SELECT queries can be paginated.'); } if (!is_callable($countQueryBuilderModifier)) { throw new InvalidArgumentException('The count query builder modifier must be a callable.'); } $this->queryBuilder = clone $queryBuilder; $this->countQueryBuilderModifier = $countQueryBuilderModifier; }
/** * Constructor. * * @param QueryBuilder $queryBuilder A DBAL query builder. * @param string $countField Primary key for the table in query. Used in count expression. Must include table alias * @param boolean $useDistinct When set to true it'll count the countfield with a distinct in front of it. * * @api */ public function __construct(QueryBuilder $queryBuilder, $countField, $useDistinct = true) { if (strpos($countField, '.') === false) { throw new LogicException('The $countField must contain a table alias in the string.'); } if (QueryBuilder::SELECT !== $queryBuilder->getType()) { throw new LogicException('Only SELECT queries can be paginated.'); } $this->queryBuilder = $queryBuilder; $this->countField = $countField; $this->useDistinct = $useDistinct; }
public function testEmptyDelete() { $qb = new QueryBuilder($this->conn); $qb2 = $qb->delete(); $this->assertEquals(QueryBuilder::DELETE, $qb->getType()); $this->assertSame($qb2, $qb); }
public function testEmptyInsert() { $qb = new QueryBuilder($this->conn); $qb2 = $qb->insert(); $this->assertEquals(QueryBuilder::INSERT, $qb->getType()); $this->assertSame($qb2, $qb); }
/** * Gets the type of the currently built query. * * @return integer */ public function getType() { return $this->queryBuilder->getType(); }
/** * Gets the type of the currently built query. * * @return int * @internal */ public function getType() : int { return $this->concreteQueryBuilder->getType(); }
/** * Gets the type of the currently built query. * * @return integer */ public function getType() { return $this->qb->getType(); }
/** * Counts the number of results that would be returned by the select query provided * * @param QueryBuilder $qb * @return int */ public function getCount(QueryBuilder $qb) { if ($qb->getType() != QueryBuilder::SELECT) { throw new \InvalidArgumentException('Query builder must be a select query'); } $select = $qb->getQueryPart('select'); $count = (int) $qb->select('COUNT(main.id)')->execute()->fetchColumn(); $qb->select($select); return $count; }
/** * Generator for SELECT queries. * * @param \Doctrine\DBAL\Query\QueryBuilder $qb * * @return \Iterator */ protected function generator(QueryBuilder $qb) { if ($qb->getType() !== QueryBuilder::SELECT) { self::raise('Generator should be used only with SELECT queries.'); } $stmt = $this->preprocess($qb); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $from = $join = []; foreach ($row as $key => $value) { // if column was preprocessed if (false !== ($pos = strpos($key, self::UNIQUE))) { $table = substr($key, 0, $pos); $column = substr($key, $pos + 6); if ($table === $this->table) { $from[$column] = $value; } else { $join[$table][$column] = $value; } } else { $from[$key] = $value; } } $class = $this->entity; $entity = new $class($from); foreach ($join as $table => $data) { // every JOIN will be set as a sub-entity $class = $this->app['arm'][$this->prefix . $table]->getEntity(); $entity[$table] = new $class($data); } (yield $entity); } }