本文整理汇总了PHP中Doctrine\ORM\Query\QueryException::tooFewParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryException::tooFewParameters方法的具体用法?PHP QueryException::tooFewParameters怎么用?PHP QueryException::tooFewParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query\QueryException
的用法示例。
在下文中一共展示了QueryException::tooFewParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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];
}
示例2: _doExecute
/**
* {@inheritdoc}
*/
protected function _doExecute()
{
$executor = $this->_parse()->getSqlExecutor();
if ($this->_queryCacheProfile) {
$executor->setQueryCacheProfile($this->_queryCacheProfile);
} else {
$executor->removeQueryCacheProfile();
}
if ($this->_resultSetMapping === null) {
$this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
}
// Prepare parameters
$paramMappings = $this->_parserResult->getParameterMappings();
$paramCount = count($this->parameters);
$mappingCount = count($paramMappings);
if ($paramCount > $mappingCount) {
throw QueryException::tooManyParameters($mappingCount, $paramCount);
} elseif ($paramCount < $mappingCount) {
throw QueryException::tooFewParameters($mappingCount, $paramCount);
}
// evict all cache for the entity region
if ($this->hasCache && isset($this->_hints[self::HINT_CACHE_EVICT]) && $this->_hints[self::HINT_CACHE_EVICT]) {
$this->evictEntityCacheRegion();
}
list($sqlParams, $types) = $this->processParameterMappings($paramMappings);
return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
}