当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::getSQL方法代码示例

本文整理汇总了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)));
     }
 }
开发者ID:Codenetz,项目名称:AclBundle,代码行数:15,代码来源:AclFilter.php

示例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));
 }
开发者ID:sergeypererva,项目名称:doctrine-extensions,代码行数:20,代码来源:FunctionsTest.php

示例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));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:22,代码来源:CountCalculatorTest.php

示例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));
 }
开发者ID:sblmasta,项目名称:doctrine-extensions,代码行数:30,代码来源:FunctionsTest.php

示例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));
 }
开发者ID:sergeyz,项目名称:doctrine-extensions,代码行数:30,代码来源:FunctionsTest.php

示例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);
 }
开发者ID:vend,项目名称:doxport,代码行数:16,代码来源:QueryAction.php

示例7: testCacheMissWhenTypeChanges

 /**
  * @depends testIssue
  */
 public function testCacheMissWhenTypeChanges(Query $query)
 {
     $query->setParameter('field', 'test', 'string');
     $this->assertStringEndsWith('.field = ?', $query->getSQL());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:8,代码来源:DDC2224Test.php

示例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;
 }
开发者ID:pigroupe,项目名称:SfynxCoreBundle,代码行数:33,代码来源:TreeRepository.php

示例9: getHash

 protected function getHash(Query $query) : string
 {
     $sql = $query->getSQL();
     $params = $query->getParameters();
     return sha1($sql . serialize($params));
 }
开发者ID:wellcommerce,项目名称:dataset,代码行数:6,代码来源:DataSetCacheManager.php


注:本文中的Doctrine\ORM\Query::getSQL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。