forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeQuery.php
More file actions
72 lines (60 loc) · 1.53 KB
/
NativeQuery.php
File metadata and controls
72 lines (60 loc) · 1.53 KB
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
<?php
declare(strict_types=1);
namespace Doctrine\ORM;
/**
* Represents a native SQL query.
*/
final class NativeQuery extends AbstractQuery
{
/**
* @var string
*/
private $sql;
/**
* Sets the SQL of the query.
*
* @param string $sql
*
* @return NativeQuery This query instance.
*/
public function setSQL($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Gets the SQL query.
*
* @return mixed The built SQL query or an array of all SQL queries.
*
* @override
*/
public function getSQL()
{
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);
}
}