diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
index 70a530046..ea4326d3b 100644
--- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
+++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
@@ -85,6 +85,58 @@ class XmlDriver extends AbstractFileDriver
}
}
+ // Evaluate native named queries
+ if (isset($xmlRoot->{'named-native-queries'})) {
+ foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) {
+ $metadata->addNamedNativeQuery(array(
+ 'name' => isset($nativeQueryElement['name']) ? (string)$nativeQueryElement['name'] : null,
+ 'query' => isset($nativeQueryElement->query) ? (string)$nativeQueryElement->query : null,
+ 'resultClass' => isset($nativeQueryElement['result-class']) ? (string)$nativeQueryElement['result-class'] : null,
+ 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string)$nativeQueryElement['result-set-mapping'] : null,
+ ));
+ }
+ }
+
+ // Evaluate sql result set mapping
+ if (isset($xmlRoot->{'sql-result-set-mappings'})) {
+ foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) {
+ $entities = array();
+ $columns = array();
+ foreach ($rsmElement as $entityElement) {
+ //
+ if (isset($entityElement['entity-class'])) {
+ $entityResult = array(
+ 'fields' => array(),
+ 'entityClass' => (string)$entityElement['entity-class'],
+ 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string)$entityElement['discriminator-column'] : null,
+ );
+
+ foreach ($entityElement as $fieldElement) {
+ $entityResult['fields'][] = array(
+ 'name' => isset($fieldElement['name']) ? (string)$fieldElement['name'] : null,
+ 'column' => isset($fieldElement['column']) ? (string)$fieldElement['column'] : null,
+ );
+ }
+
+ $entities[] = $entityResult;
+ }
+
+ //
+ if (isset($entityElement['name'])) {
+ $columns[] = array(
+ 'name' => (string)$entityElement['name'],
+ );
+ }
+ }
+
+ $metadata->addSqlResultSetMapping(array(
+ 'name' => (string)$rsmElement['name'],
+ 'entities' => $entities,
+ 'columns' => $columns
+ ));
+ }
+ }
+
/* not implemented specially anyway. use table = schema.table
if (isset($xmlRoot['schema'])) {
$metadata->table['schema'] = (string)$xmlRoot['schema'];
diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
index 6e0ff36e5..df7490132 100644
--- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
+++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
@@ -495,7 +495,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testNamedNativeQuery()
{
- if (!$this instanceof AnnotationDriverTest) {
+ if (!$this instanceof AnnotationDriverTest && !$this instanceof XmlMappingDriverTest) {
$this->markTestIncomplete();
}
@@ -551,7 +551,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testSqlResultSetMapping()
{
- if (!$this instanceof AnnotationDriverTest) {
+ if (!$this instanceof AnnotationDriverTest && !$this instanceof XmlMappingDriverTest) {
$this->markTestIncomplete();
}
diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml
new file mode 100644
index 000000000..a65d08371
--- /dev/null
+++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+ SELECT id, country, city FROM cms_addresses
+
+
+
+ SELECT * FROM cms_addresses WHERE id = ?
+
+
+
+ SELECT COUNT(*) AS count FROM cms_addresses
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml
new file mode 100644
index 000000000..1045deba9
--- /dev/null
+++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml
@@ -0,0 +1,121 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ SELECT id, username FROM cms_users WHERE username = ?
+
+
+
+ SELECT * FROM cms_users WHERE username = ?
+
+
+
+ SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?
+
+
+
+ SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?
+
+
+
+ SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml
new file mode 100644
index 000000000..6902b7366
--- /dev/null
+++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+ SELECT id, name, discr FROM company_persons ORDER BY name
+
+
+
+
+
+ SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file