1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\ORM; |
||
6 | |||
7 | use function array_values; |
||
8 | use function is_int; |
||
9 | use function key; |
||
10 | use function ksort; |
||
11 | |||
12 | /** |
||
13 | * Represents a native SQL query. |
||
14 | */ |
||
15 | final class NativeQuery extends AbstractQuery |
||
16 | { |
||
17 | /** @var string */ |
||
18 | private $sql; |
||
19 | |||
20 | /** |
||
21 | * Sets the SQL of the query. |
||
22 | * |
||
23 | * @param string $sql |
||
24 | * |
||
25 | * @return NativeQuery This query instance. |
||
26 | */ |
||
27 | 13 | public function setSQL($sql) |
|
28 | { |
||
29 | 13 | $this->sql = $sql; |
|
30 | |||
31 | 13 | return $this; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Gets the SQL query. |
||
36 | * |
||
37 | * @return mixed The built SQL query or an array of all SQL queries. |
||
38 | * |
||
39 | * @override |
||
40 | */ |
||
41 | 2 | public function getSQL() |
|
42 | { |
||
43 | 2 | return $this->sql; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | 14 | protected function doExecute() |
|
50 | { |
||
51 | 14 | $parameters = []; |
|
52 | 14 | $types = []; |
|
53 | |||
54 | 14 | foreach ($this->getParameters() as $parameter) { |
|
55 | 11 | $name = $parameter->getName(); |
|
56 | 11 | $value = $this->processParameterValue($parameter->getValue()); |
|
57 | 11 | $type = ($parameter->getValue() === $value) |
|
58 | 11 | ? $parameter->getType() |
|
59 | 11 | : Query\ParameterTypeInferer::inferType($value); |
|
60 | |||
61 | 11 | $parameters[$name] = $value; |
|
62 | 11 | $types[$name] = $type; |
|
63 | } |
||
64 | |||
65 | 14 | if ($parameters && is_int(key($parameters))) { |
|
66 | 11 | ksort($parameters); |
|
67 | 11 | ksort($types); |
|
68 | |||
69 | 11 | $parameters = array_values($parameters); |
|
70 | 11 | $types = array_values($types); |
|
71 | } |
||
72 | |||
73 | 14 | return $this->em->getConnection()->executeQuery($this->sql, $parameters, $types, $this->queryCacheProfile); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
74 | } |
||
75 | } |
||
76 |