. */ namespace Doctrine\ORM; /** * Represents a native SQL query. * * @author Roman Borschel * @since 2.0 */ final class NativeQuery extends AbstractQuery { private $_sql; /** * Initializes a new instance of the NativeQuery class that is bound * to the given EntityManager. * * @param EntityManager $em The EntityManager to use. */ public function __construct(EntityManager $em) { parent::__construct($em); } /** * Sets the SQL of the query. * * @param string $sql * @return Doctrine\ORM\AbstractQuery */ 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; } /** * Executes the query. * * @param array $params * @return Statement The Statement handle. * @override */ protected function _doExecute(array $params) { return $this->_em->getConnection()->execute($this->_sql, $this->_prepareParams($params)); } /** * {@inheritdoc} * * @override */ protected function _prepareParams(array $params) { $sqlParams = array(); foreach ($params as $key => $value) { $sqlParams[$key] = $value; } ksort($sqlParams); return array_values($sqlParams); } }