forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNativeQuery.php
76 lines (63 loc) · 1.54 KB
/
NativeQuery.php
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
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace Doctrine\ORM;
use function array_values;
use function is_int;
use function key;
use function ksort;
/**
* Represents a native SQL query.
*/
final class NativeQuery extends AbstractQuery
{
/** @var string */
private $sql;
/**
* Sets the SQL of the query.
*
* @param string $sql
*
* @return $this
*/
public function setSQL($sql): self
{
$this->sql = $sql;
return $this;
}
/**
* Gets the SQL query.
*/
public function getSQL(): string
{
return $this->sql;
}
/**
* {@inheritdoc}
*/
protected function _doExecute()
{
$parameters = [];
$types = [];
foreach ($this->getParameters() as $parameter) {
$name = $parameter->getName();
$value = $this->processParameterValue($parameter->getValue());
$type = $parameter->getValue() === $value
? $parameter->getType()
: Query\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
);
}
}