本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder::getSQL方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::getSQL方法的具体用法?PHP QueryBuilder::getSQL怎么用?PHP QueryBuilder::getSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Query\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::getSQL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSQLDelegatesToConcreteQueryBuilder
/**
* @test
*/
public function getSQLDelegatesToConcreteQueryBuilder()
{
$this->concreteQueryBuilder->getSQL()->shouldBeCalled()->willReturn('UPDATE aTable SET pid = 7');
$this->concreteQueryBuilder->getType()->willReturn(2);
// Update Type
$this->subject->getSQL();
}
示例2: logBuilder
/**
* @param QueryBuilder $builder
*/
public static function logBuilder($builder)
{
$sql = $builder->getSQL();
$params = $builder->getParameters();
self::log("Running Query: " . $sql . " with params:");
self::logObject($params);
}
示例3: addQueryFromBuilder
/**
* Add a query from a query builder
*
* @param QueryBuilder $qb
* @return $this
*/
public function addQueryFromBuilder(QueryBuilder $qb)
{
/**
* @TODO : How to manage query params ?
*/
$this->queries[] = new Query($qb->getSQL());
return $this;
}
示例4: getNextAlias
/**
* @param QueryBuilder $query The query builder
*
* @return string
*/
private function getNextAlias($query)
{
if (!preg_match_all('~\\b(\\w+)\\.~', $query->getSQL(), $matches)) {
return 'b';
}
$aliases = array_unique($matches[1]);
for ($alias = 'b'; in_array($alias, $aliases); $alias++) {
continue;
}
return $alias;
}
示例5: getSQL
/**
* {@inheritdoc}
*/
public function getSQL()
{
return $this->qb->getSQL();
}
示例6: current
public function current()
{
return $this->dbal->fetchAll($this->qb->getSQL());
}
示例7: createQuery
/**
* @param QueryBuilder $qb
*
* @return NativeQuery
*/
private function createQuery(QueryBuilder $qb)
{
$query = $this->em->createNativeQuery($qb->getSQL(), $this->rsm);
$query->setParameters($this->qb->getParameters());
return $query;
}
示例8: testGetState
public function testGetState()
{
$qb = new QueryBuilder($this->conn);
$this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
$qb->select('u.*')->from('users', 'u');
$this->assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
$sql1 = $qb->getSQL();
$this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
$this->assertEquals($sql1, $qb->getSQL());
}
示例9: testSelectFromMasterWithWhereOnJoinedTables
/**
* @group DBAL-172
*/
public function testSelectFromMasterWithWhereOnJoinedTables()
{
$qb = new QueryBuilder($this->conn);
$qb->select('COUNT(DISTINCT news.id)')->from('newspages', 'news')->innerJoin('news', 'nodeversion', 'nv', "nv.refId = news.id AND nv.refEntityname='Entity\\News'")->innerJoin('nv', 'nodetranslation', 'nt', 'nv.nodetranslation = nt.id')->innerJoin('nt', 'node', 'n', 'nt.node = n.id')->where('nt.lang = ?')->andWhere('n.deleted = 0');
$this->assertEquals("SELECT COUNT(DISTINCT news.id) FROM newspages news INNER JOIN nodeversion nv ON nv.refId = news.id AND nv.refEntityname='Entity\\News' INNER JOIN nodetranslation nt ON nv.nodetranslation = nt.id INNER JOIN node n ON nt.node = n.id WHERE (nt.lang = ?) AND (n.deleted = 0)", $qb->getSQL());
}
示例10: testJoinWithNonUniqueAliasThrowsException
/**
* @group DBAL-1137
*/
public function testJoinWithNonUniqueAliasThrowsException()
{
$qb = new QueryBuilder($this->conn);
$qb->select('a.id')->from('table_a', 'a')->join('a', 'table_b', 'a', 'a.fk_b = a.id');
$this->setExpectedException('Doctrine\\DBAL\\Query\\QueryException', "The given alias 'a' is not unique in FROM and JOIN clause table. The currently registered aliases are: a.");
$qb->getSQL();
}
示例11: getSQL
/**
* Gets the complete SQL string formed by the current specifications of this QueryBuilder.
*
* <code>
* $qb = $conn->getQueryBuilder()
* ->select('u')
* ->from('User', 'u')
* echo $qb->getSQL(); // SELECT u FROM User u
* </code>
*
* @return string The SQL query string.
*/
public function getSQL()
{
return $this->queryBuilder->getSQL();
}
示例12: testReferenceJoinFromJoin
/**
* @group DBAL-172
*/
public function testReferenceJoinFromJoin()
{
$qb = new QueryBuilder($this->conn);
$qb->select("l.id", "mdsh.xcode", "mdso.xcode")->from("location_tree", "l")->join("l", "location_tree_pos", "p", "l.id = p.tree_id")->rightJoin("l", "hotel", "h", "h.location_id = l.id")->leftJoin("l", "offer_location", "ol", "l.id=ol.location_id")->leftJoin("ol", "mds_offer", "mdso", "ol.offer_id = mdso.offer_id")->leftJoin("h", "mds_hotel", "mdsh", "h.id = mdsh.hotel_id")->where("p.parent_id IN (:ids)")->andWhere("(mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)");
$this->setExpectedException('Doctrine\\DBAL\\Query\\QueryException', "The given alias 'ol' is not part of any FROM clause table. The currently registered FROM-clause aliases are: l");
$this->assertEquals('', $qb->getSQL());
}
示例13: testSelectWithMultipleFromAndJoins
/**
* @group DBAL-442
*/
public function testSelectWithMultipleFromAndJoins()
{
$qb = new QueryBuilder($this->conn);
$qb->select('DISTINCT u.id')->from('users', 'u')->from('articles', 'a')->innerJoin('u', 'permissions', 'p', 'p.user_id = u.id')->innerJoin('a', 'comments', 'c', 'c.article_id = a.id')->where('u.id = a.user_id')->andWhere('p.read = 1');
$this->assertEquals('SELECT DISTINCT u.id FROM users u INNER JOIN permissions p ON p.user_id = u.id, articles a INNER JOIN comments c ON c.article_id = a.id WHERE (u.id = a.user_id) AND (p.read = 1)', $qb->getSQL());
}
示例14: testComplexSelectWithSomeTableAliases
public function testComplexSelectWithSomeTableAliases()
{
$qb = new QueryBuilder($this->conn);
$qb->select('u.id')->from('users', 'u')->from('articles')->innerJoin('u', 'permissions', 'p', 'p.user_id = u.id')->innerJoin('articles', 'comments', 'c', 'c.article_id = articles.id');
$this->assertEquals('SELECT u.id FROM users u INNER JOIN permissions p ON p.user_id = u.id, articles INNER JOIN comments c ON c.article_id = articles.id', $qb->getSQL());
}
示例15: formatQuery
/**
* Format SQL query by replacing {x} and {x.y} tokens.
*
* @staticvar string $re
*
* @param \Doctrine\DBAL\Query\QueryBuilder $qb
* @param array $tables
*
* @throws \Lokhman\Silex\ARM\Exception\RepositoryException
* @return string
*/
private function formatQuery(QueryBuilder $qb, array $tables)
{
static $re = '/("|\').*?\\1(*SKIP)(*FAIL)|\\{(?:[^{}]|(?R))*\\}/';
return preg_replace_callback($re, function ($matches) use($tables) {
if (false !== ($pos = strpos($token = substr($matches[0], 1, -1), '.'))) {
if (!isset($tables[$alias = substr($token, 0, $pos)])) {
self::raise('No repository registered for "' . $alias . '".');
}
return $tables[$alias]->getTable() . self::UNIQUE . substr($token, $pos + 1);
} elseif (in_array($token, $this->metadata->getColumns())) {
return $this->table . self::UNIQUE . $token;
} else {
return $matches[0];
}
}, $qb->getSQL());
}