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


PHP Query\QueryException类代码示例

本文整理汇总了PHP中Doctrine\ORM\Query\QueryException的典型用法代码示例。如果您正苦于以下问题:PHP QueryException类的具体用法?PHP QueryException怎么用?PHP QueryException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QueryException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processParameterMappings

 /**
  * @param Query                              $query
  * @param array                              $paramMappings
  * @return array
  * @throws \Doctrine\ORM\Query\QueryException
  */
 protected function processParameterMappings(Query $query, $paramMappings)
 {
     $sqlParams = array();
     $types = array();
     /** @var Parameter $parameter */
     foreach ($query->getParameters() as $parameter) {
         $key = $parameter->getName();
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         $value = $query->processParameterValue($parameter->getValue());
         $type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
         foreach ($paramMappings[$key] as $position) {
             $types[$position] = $type;
         }
         $sqlPositions = $paramMappings[$key];
         $value = array($value);
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) != count($types)) {
         throw QueryException::parameterTypeMissmatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return array($sqlParams, $types);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:39,代码来源:QueryCountCalculator.php

示例2: testwithException_throwsPscDoctrineQueryException

 /**
  * @expectedException Psc\Doctrine\QueryException
  */
 public function testwithException_throwsPscDoctrineQueryException()
 {
     $query = $this->doublesManager->createQueryMock(array('getResult', 'getScalarResult', 'getDQL'), $this->emm);
     $query->expects($this->once())->method('getDQL')->will($this->returnValue('SELECT * FROM DAM\\AGE'));
     $query->expects($this->once())->method('getResult')->will($this->throwException(\Doctrine\ORM\Query\QueryException::semanticalError('DAM\\AGE ist keine Tabelle natürlich')));
     $this->runDeliverQuery(NULL, 'result', $query);
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:10,代码来源:EntityRepositoryDeliverQueryTest.php

示例3: getSql

 /**
  * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
  * @return string
  * @throws QueryException
  */
 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $unit = strtoupper(is_string($this->unit) ? $this->unit : $this->unit->value);
     if (!in_array($unit, self::$allowedUnits)) {
         throw QueryException::semanticalError('DATE_SUB() does not support unit "' . $unit . '".');
     }
     return 'DATE_SUB(' . $this->firstDateExpression->dispatch($sqlWalker) . ', INTERVAL ' . $this->intervalExpression->dispatch($sqlWalker) . ' ' . $unit . ')';
 }
开发者ID:guiwoda,项目名称:DoctrineExtensions,代码行数:13,代码来源:DateSub.php

示例4: create

 /**
  * Create platform function node.
  *
  * @param string $platformName
  * @param string $functionName
  * @param array $parameters
  * @throws \Doctrine\ORM\Query\QueryException
  * @return PlatformFunctionNode
  */
 public static function create($platformName, $functionName, array $parameters)
 {
     $className = __NAMESPACE__ . '\\Platform\\Functions\\' . Inflector::classify(strtolower($platformName)) . '\\' . Inflector::classify(strtolower($functionName));
     if (!class_exists($className)) {
         throw QueryException::syntaxError(sprintf('Function "%s" does not supported for platform "%s"', $functionName, $platformName));
     }
     return new $className($parameters);
 }
开发者ID:Hikariii,项目名称:doctrine-extensions,代码行数:17,代码来源:FunctionFactory.php

示例5: __construct

 /**
  * @param string $value
  *
  * @throws \Doctrine\ORM\Query\QueryException
  */
 public function __construct($value)
 {
     if (strlen($value) == 1) {
         throw \Doctrine\ORM\Query\QueryException::invalidParameterFormat($value);
     }
     $param = substr($value, 1);
     $this->isNamed = !is_numeric($param);
     $this->name = $param;
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:14,代码来源:InputParameter.php

示例6: getSql

 /**
  * @override
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     switch (strtolower($this->unit->value)) {
         case 'day':
             return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
         case 'month':
             return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
         default:
             throw QueryException::semanticalError('DATE_ADD() only supports units of type day and month.');
     }
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:14,代码来源:DateAddFunction.php

示例7: getSql

 public function getSql(SqlWalker $sqlWalker)
 {
     $unit = strtolower($this->unit);
     if ($unit == "day") {
         return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
     } else {
         if ($unit == "month") {
             return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression($this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker));
         } else {
             throw QueryException::semanticalError('DATE_ADD() only supports units of type day and month.');
         }
     }
 }
开发者ID:krishcdbry,项目名称:z-zangura,代码行数:13,代码来源:DateAddFunction.php

示例8: processParameterMappings

 /**
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * Copy of Doctrine\ORM\Query::processParameterMappings
  *
  * @param Query $query
  * @return array
  * @throws QueryException
  */
 public function processParameterMappings(Query $query)
 {
     $parser = new Parser($query);
     $parseResult = $parser->parse();
     $paramMappings = $parseResult->getParameterMappings();
     $resultSetMapping = $parseResult->getResultSetMapping();
     $paramCount = count($query->getParameters());
     $mappingCount = count($paramMappings);
     if ($paramCount > $mappingCount) {
         throw QueryException::tooManyParameters($mappingCount, $paramCount);
     } elseif ($paramCount < $mappingCount) {
         throw QueryException::tooFewParameters($mappingCount, $paramCount);
     }
     $sqlParams = [];
     $types = [];
     foreach ($query->getParameters() as $parameter) {
         $key = $parameter->getName();
         $value = $parameter->getValue();
         $rsm = $resultSetMapping;
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($rsm->metadataParameterMapping[$key]) && $value instanceof ClassMetadata) {
             $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]);
         }
         $value = $query->processParameterValue($value);
         $type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
         foreach ($paramMappings[$key] as $position) {
             $types[$position] = $type;
         }
         $sqlPositions = $paramMappings[$key];
         // optimized multi value sql positions away for now,
         // they are not allowed in DQL anyways.
         $value = [$value];
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) !== count($types)) {
         throw QueryException::parameterTypeMismatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return [$sqlParams, $types];
 }
开发者ID:startupz,项目名称:platform-1,代码行数:60,代码来源:NativeQueryExecutorHelper.php

示例9: syntaxError

 /**
  * Generates a new syntax error.
  *
  * @param string $expected Expected string.
  * @param array $token Got token.
  *
  * @throws \Doctrine\ORM\Query\QueryException
  */
 public function syntaxError($expected = '', $token = null)
 {
     if ($token === null) {
         $token = $this->_lexer->lookahead;
     }
     $tokenPos = isset($token['position']) ? $token['position'] : '-1';
     $message = "line 0, col {$tokenPos}: Error: ";
     if ($expected !== '') {
         $message .= "Expected {$expected}, got ";
     } else {
         $message .= 'Unexpected ';
     }
     if ($this->_lexer->lookahead === null) {
         $message .= 'end of string.';
     } else {
         $message .= "'{$token['value']}'";
     }
     throw QueryException::syntaxError($message);
 }
开发者ID:OmondiKevin,项目名称:ADT_MTRH,代码行数:27,代码来源:Parser.php

示例10: execute

 /**
  * Executes the query.
  *
  * @param string $params Any additional query parameters.
  * @param integer $hydrationMode Processing mode to be used during the hydration process.
  * @return mixed
  */
 public function execute($params = array(), $hydrationMode = null)
 {
     // If there are still pending insertions in the UnitOfWork we need to flush
     // in order to guarantee a correct result.
     if ($this->_em->getUnitOfWork()->hasPendingInsertions()) {
         $this->_em->flush();
     }
     if ($hydrationMode !== null) {
         $this->_hydrationMode = $hydrationMode;
     }
     $params = $this->getParameters($params);
     if (isset($params[0])) {
         throw QueryException::invalidParameterPosition(0);
     }
     // Check result cache
     if ($this->_useResultCache && ($cacheDriver = $this->getResultCacheDriver())) {
         $id = $this->getResultCacheId($params);
         $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
         if ($cached === false) {
             // Cache miss.
             $stmt = $this->_doExecute($params);
             $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
             $cacheDriver->save($id, $result, $this->_resultCacheTTL);
             return $result;
         } else {
             // Cache hit.
             return $cached;
         }
     }
     $stmt = $this->_doExecute($params);
     if (is_numeric($stmt)) {
         return $stmt;
     }
     return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
 }
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:42,代码来源:AbstractQuery.php

示例11: _doExecute

 /**
  * {@inheritdoc}
  */
 protected function _doExecute()
 {
     $executor = $this->_parse()->getSqlExecutor();
     // Prepare parameters
     $paramMappings = $this->_parserResult->getParameterMappings();
     if (count($paramMappings) != count($this->_params)) {
         throw QueryException::invalidParameterNumber();
     }
     $sqlParams = $types = array();
     foreach ($this->_params as $key => $value) {
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($this->_paramTypes[$key])) {
             foreach ($paramMappings[$key] as $position) {
                 $types[$position] = $this->_paramTypes[$key];
             }
         }
         if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value))) {
             if ($this->_em->getUnitOfWork()->getEntityState($value) == UnitOfWork::STATE_MANAGED) {
                 $idValues = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
             } else {
                 $class = $this->_em->getClassMetadata(get_class($value));
                 $idValues = $class->getIdentifierValues($value);
             }
             $sqlPositions = $paramMappings[$key];
             $cSqlPos = count($sqlPositions);
             $cIdValues = count($idValues);
             $idValues = array_values($idValues);
             for ($i = 0; $i < $cSqlPos; $i++) {
                 $sqlParams[$sqlPositions[$i]] = $idValues[$i % $cIdValues];
             }
         } else {
             foreach ($paramMappings[$key] as $position) {
                 $sqlParams[$position] = $value;
             }
         }
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
     }
     if ($this->_resultSetMapping === null) {
         $this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
     }
     return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
 }
开发者ID:krishcdbry,项目名称:z-zangura,代码行数:50,代码来源:Query.php

示例12: processParameterMappings

 /**
  * Processes query parameter mappings
  * 
  * @param array $paramMappings
  * @return array
  */
 private function processParameterMappings($paramMappings)
 {
     $sqlParams = $types = array();
     foreach ($this->_params as $key => $value) {
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($this->_paramTypes[$key])) {
             foreach ($paramMappings[$key] as $position) {
                 $types[$position] = $this->_paramTypes[$key];
             }
         }
         $sqlPositions = $paramMappings[$key];
         $value = array_values($this->processParameterValue($value));
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
     }
     return array($sqlParams, $types);
 }
开发者ID:ramonornela,项目名称:doctrine2,代码行数:31,代码来源:Query.php

示例13: semanticalError

 /**
  * Generates a new semantical error.
  *
  * @param string     $message Optional message.
  * @param array|null $token   Optional token.
  *
  * @return void
  *
  * @throws \Doctrine\ORM\Query\QueryException
  */
 public function semanticalError($message = '', $token = null)
 {
     if ($token === null) {
         $token = $this->lexer->lookahead;
     }
     // Minimum exposed chars ahead of token
     $distance = 12;
     // Find a position of a final word to display in error string
     $dql = $this->query->getDql();
     $length = strlen($dql);
     $pos = $token['position'] + $distance;
     $pos = strpos($dql, ' ', $length > $pos ? $pos : $length);
     $length = $pos !== false ? $pos - $token['position'] : $distance;
     $tokenPos = isset($token['position']) && $token['position'] > 0 ? $token['position'] : '-1';
     $tokenStr = substr($dql, $token['position'], $length);
     // Building informative message
     $message = 'line 0, col ' . $tokenPos . " near '" . $tokenStr . "': Error: " . $message;
     throw QueryException::semanticalError($message, QueryException::dqlError($this->query->getDQL()));
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:29,代码来源:Parser.php

示例14: walkLiteral

 /**
  * {@inheritdoc}
  */
 public function walkLiteral($literal)
 {
     switch ($literal->type) {
         case AST\Literal::STRING:
             return $this->conn->quote($literal->value);
         case AST\Literal::BOOLEAN:
             $bool = strtolower($literal->value) == 'true' ? true : false;
             $boolVal = $this->conn->getDatabasePlatform()->convertBooleans($bool);
             return $boolVal;
         case AST\Literal::NUMERIC:
             return $literal->value;
         default:
             throw QueryException::invalidLiteral($literal);
     }
 }
开发者ID:nemekzg,项目名称:doctrine2,代码行数:18,代码来源:SqlWalker.php

示例15: execute

 /**
  * Executes the query.
  *
  * @param array $params Any additional query parameters.
  * @param integer $hydrationMode Processing mode to be used during the hydration process.
  * @return mixed
  */
 public function execute($params = array(), $hydrationMode = null)
 {
     if ($hydrationMode !== null) {
         $this->setHydrationMode($hydrationMode);
     }
     if ($params) {
         $this->setParameters($params);
     }
     if (isset($this->_params[0])) {
         throw QueryException::invalidParameterPosition(0);
     }
     // Check result cache
     if ($this->_useResultCache && ($cacheDriver = $this->getResultCacheDriver())) {
         list($key, $hash) = $this->getResultCacheId();
         $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($hash);
         if ($cached === false || !isset($cached[$key])) {
             // Cache miss.
             $stmt = $this->_doExecute();
             $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
             $cacheDriver->save($hash, array($key => $result), $this->_resultCacheTTL);
             return $result;
         } else {
             // Cache hit.
             return $cached[$key];
         }
     }
     $stmt = $this->_doExecute();
     if (is_numeric($stmt)) {
         return $stmt;
     }
     return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
 }
开发者ID:Niggu,项目名称:cloudrexx,代码行数:39,代码来源:AbstractQuery.php


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