本文整理汇总了PHP中Doctrine\ORM\Query::getSQL方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::getSQL方法的具体用法?PHP Query::getSQL怎么用?PHP Query::getSQL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::getSQL方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSqlCriteria
/**
* @param Query|QueryBuilder $criteria
*
* @return string (sql)
*/
protected function getSqlCriteria($criteria)
{
if ($criteria instanceof QueryBuilder) {
return $criteria->getQuery()->getSQL();
} elseif ($criteria instanceof Query) {
return $criteria->getSQL();
} else {
throw new \Exception(sprintf('Criteria must be instance of Query or QueryBuilder, instance of %s given', get_class($criteria)));
}
}
示例2: testDqlFunction
/**
* @dataProvider functionsDataProvider
* @param array $functions
* @param string $dql
* @param string $sql
* @param string $expectedResult
*/
public function testDqlFunction(array $functions, $dql, $sql, $expectedResult)
{
$configuration = $this->entityManager->getConfiguration();
foreach ($functions as $function) {
$this->registerDqlFunction($function['type'], $function['name'], $function['className'], $configuration);
}
$query = new Query($this->entityManager);
$query->setDQL($dql);
$this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql));
$result = $query->getArrayResult();
$this->assertNotEmpty($result);
$this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql));
}
示例3: testCalculateCount
/**
* @param string $dql
* @param array $sqlParameters
* @param array $types
* @param array $queryParameters
*
* @dataProvider getCountDataProvider
*/
public function testCalculateCount($dql, array $sqlParameters, array $types, array $queryParameters = array())
{
/** @var $entityManager EntityManager|\PHPUnit_Framework_MockObject_MockObject */
/** @var $connection Connection|\PHPUnit_Framework_MockObject_MockObject */
/** @var $statement Statement|\PHPUnit_Framework_MockObject_MockObject */
list($entityManager, $connection, $statement) = $this->prepareMocks();
$query = new Query($entityManager);
$query->setDQL($dql);
$query->setParameters($queryParameters);
$expectedSql = 'SELECT COUNT(*) FROM (' . $query->getSQL() . ') AS e';
$connection->expects($this->once())->method('executeQuery')->with($expectedSql, $sqlParameters, $types)->will($this->returnValue($statement));
$statement->expects($this->once())->method('fetchColumn')->with()->will($this->returnValue(self::TEST_COUNT));
$this->assertEquals(self::TEST_COUNT, QueryCountCalculator::calculateCount($query));
}
示例4: testDqlFunction
/**
* @dataProvider functionsDataProvider
* @param array $functions
* @param string $dql
* @param string $sql
* @param string $expectedResult
*/
public function testDqlFunction(array $functions, $dql, $sql, $expectedResult)
{
$configuration = $this->entityManager->getConfiguration();
foreach ($functions as $function) {
$this->registerDqlFunction($function['type'], $function['name'], $function['className'], $configuration);
}
$query = new Query($this->entityManager);
$query->setDQL($dql);
if (is_array($sql)) {
$constraints = array();
foreach ($sql as $sqlVariant) {
$constraints[] = $this->equalTo($sqlVariant);
}
$constraint = new \PHPUnit_Framework_Constraint_Or();
$constraint->setConstraints($constraints);
$this->assertThat($query->getSQL(), $constraint);
} else {
$this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql));
}
$result = $query->getArrayResult();
$this->assertNotEmpty($result);
$this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql));
}
示例5: testDateFunction
/**
* @dataProvider functionsDataProvider
* @param string $type
* @param string $functionName
* @param string $functionClass
* @param string $dql
* @param string $sql
* @param string $expectedResult
*/
public function testDateFunction($type, $functionName, $functionClass, $dql, $sql, $expectedResult)
{
$configuration = $this->entityManager->getConfiguration();
switch ($type) {
case 'datetime':
$configuration->addCustomDatetimeFunction($functionName, $functionClass);
break;
case 'numeric':
$configuration->addCustomNumericFunction($functionName, $functionClass);
break;
case 'string':
default:
$configuration->addCustomStringFunction($functionName, $functionClass);
}
$query = new Query($this->entityManager);
$query->setDQL($dql);
$this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql));
$result = $query->getArrayResult();
$this->assertNotEmpty($result);
$this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql));
}
示例6: debugQuery
/**
* Prints debugging information about the given query
*
* @param Query $query
*/
protected function debugQuery(Query $query)
{
if (!$this->options['verbose']) {
return;
}
$sql = $query->getSQL();
if (is_array($sql)) {
$sql = implode('; ', $sql);
}
$this->logger->info($sql);
}
示例7: testCacheMissWhenTypeChanges
/**
* @depends testIssue
*/
public function testCacheMissWhenTypeChanges(Query $query)
{
$query->setParameter('field', 'test', 'string');
$this->assertStringEndsWith('.field = ?', $query->getSQL());
}
示例8: cacheQuery
/**
* return query in cache
*
* @param Query $query
* @param integer $time
* @param string $MODE [MODE_GET, MODE_PUT , MODE_NORMAL , MODE_REFRESH]
* @param boolean $setCacheable
* @param string $namespace
* @param string $input_hash
*
* @return Query
* @access public
* @author Etienne de Longeaux <etienne.delongeaux@gmail.com>
*/
public function cacheQuery(Query $query, $time = 3600, $MODE = 3, $setCacheable = true, $namespace = '', $input_hash = '')
{
if (!$query) {
throw new \Gedmo\Exception\InvalidArgumentException('Invalide query instance');
}
// create single file from all input
if (empty($input_hash)) {
$input_hash = $namespace . sha1(serialize($query->getParameters()) . $query->getSQL());
}
$query->useResultCache(true, $time, (string) $input_hash);
$query->useQueryCache(true);
if (method_exists($query, 'setCacheMode')) {
$query->setCacheMode($MODE);
}
if (method_exists($query, 'setCacheable')) {
$query->setCacheable($setCacheable);
}
return $query;
}
示例9: getHash
protected function getHash(Query $query) : string
{
$sql = $query->getSQL();
$params = $query->getParameters();
return sha1($sql . serialize($params));
}