blob: 6cee0e843fb952ed10d3465911df913a3f481970 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
declare(strict_types=1);
namespace Doctrine\ORM;
use Doctrine\DBAL\Result;
use Doctrine\ORM\Query\ParameterTypeInferer;
use function array_values;
use function is_int;
use function key;
use function ksort;
/**
* Represents a native SQL query.
*
* @final
*/
class NativeQuery extends AbstractQuery
{
private string $sql;
/** @return $this */
public function setSQL(string $sql): self
{
$this->sql = $sql;
return $this;
}
public function getSQL(): string
{
return $this->sql;
}
protected function _doExecute(): Result|int
{
$parameters = [];
$types = [];
foreach ($this->getParameters() as $parameter) {
$name = $parameter->getName();
$value = $this->processParameterValue($parameter->getValue());
$type = $parameter->getValue() === $value
? $parameter->getType()
: ParameterTypeInferer::inferType($value);
$parameters[$name] = $value;
$types[$name] = $type;
}
if ($parameters && is_int(key($parameters))) {
ksort($parameters);
ksort($types);
$parameters = array_values($parameters);
$types = array_values($types);
}
return $this->em->getConnection()->executeQuery(
$this->sql,
$parameters,
$types,
$this->queryCacheProfile,
);
}
}
|