Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / NativeQuery.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18  */
19
20 namespace Doctrine\ORM;
21
22 /**
23  * Represents a native SQL query.
24  *
25  * @author Roman Borschel <roman@code-factory.org>
26  * @since 2.0
27  */
28 final class NativeQuery extends AbstractQuery
29 {
30     private $_sql;
31
32     /**
33      * Sets the SQL of the query.
34      *
35      * @param string $sql
36      * @return NativeQuery This query instance.
37      */
38     public function setSQL($sql)
39     {
40         $this->_sql = $sql;
41
42         return $this;
43     }
44
45     /**
46      * Gets the SQL query.
47      *
48      * @return mixed The built SQL query or an array of all SQL queries.
49      * @override
50      */
51     public function getSQL()
52     {
53         return $this->_sql;
54     }
55
56     /**
57      * {@inheritdoc}
58      */
59     protected function _doExecute()
60     {
61         $parameters = array();
62         $types      = array();
63
64         foreach ($this->getParameters() as $parameter) {
65             $name  = $parameter->getName();
66             $value = $this->processParameterValue($parameter->getValue());
67             $type  = ($parameter->getValue() === $value)
68                 ? $parameter->getType()
69                 : Query\ParameterTypeInferer::inferType($value);
70
71             $parameters[$name] = $value;
72             $types[$name]      = $type;
73         }
74
75         if ($parameters && is_int(key($parameters))) {
76             ksort($parameters);
77             ksort($types);
78
79             $parameters = array_values($parameters);
80             $types      = array_values($types);
81         }
82
83         return $this->_em->getConnection()->executeQuery(
84             $this->_sql, $parameters, $types, $this->_queryCacheProfile
85         );
86     }
87 }