/** * @return NativeQueryWrapper */ public function getQuery() { $query = new Doctrine\ORM\NativeQuery($this->em); $query->setResultSetMapping($this->getResultSetMapper()); $query->setParameters($this->getParameters()); $wrapped = new NativeQueryWrapper($query); $wrapped->setFirstResult($this->getFirstResult()); $wrapped->setMaxResults($this->getMaxResults()); $hasSelect = (bool) $this->getQueryPart('select'); if (!$hasSelect && $this->getType() === self::SELECT) { $select = $this->getResultSetMapper()->generateSelectClause(); $this->select($select ?: '*'); } $query->setSQL($this->getSQL()); $this->setFirstResult($wrapped->getFirstResult()); $this->setMaxResults($wrapped->getMaxResults()); if (!$hasSelect && $this->getType() === self::SELECT) { $this->resetQueryPart('select'); } $rsm = $this->getResultSetMapper(); if (empty($rsm->fieldMappings) && empty($rsm->scalarMappings)) { throw new InvalidStateException("No field or columns mapping found, please configure the ResultSetMapper and some fields."); } return $wrapped; }
/** * {@inheritDoc} */ public function createNativeQuery($sql, ResultSetMapping $rsm) { $query = new NativeQuery($this); $query->setSql($sql); $query->setResultSetMapping($rsm); return $query; }
public function setResultSetMapping(Query\ResultSetMapping $rsm) { $this->nativeQuery->setResultSetMapping($rsm); return $this; }