From d8d761b593a7f7e7faf51c852c4272d0ff79f06d Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Mon, 2 Jun 2008 15:00:50 +0000 Subject: [PATCH] Fixes in ParserResult, which was generating a bad table alias. Added more test cases. Commented new Event system call in EntityManager. Fixes in RangeVariableDeclaration. --- lib/Doctrine/EntityManager.php | 2 +- lib/Doctrine/Query/ParserResult.php | 6 ++++++ .../Query/Production/RangeVariableDeclaration.php | 9 ++++++--- tests/Orm/Query/SelectSqlGenerationTest.php | 7 +++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/EntityManager.php b/lib/Doctrine/EntityManager.php index 53aa670b4..793f8c0aa 100644 --- a/lib/Doctrine/EntityManager.php +++ b/lib/Doctrine/EntityManager.php @@ -140,7 +140,7 @@ class Doctrine_EntityManager $this->_metadataFactory = new Doctrine_ClassMetadata_Factory( $this, new Doctrine_ClassMetadata_CodeDriver()); $this->_unitOfWork = new Doctrine_Connection_UnitOfWork($conn); - $this->_eventManager = new Doctrine_EventManager(); + //$this->_eventManager = new Doctrine_EventManager(); if ($name !== null) { self::$_ems[$name] = $this; diff --git a/lib/Doctrine/Query/ParserResult.php b/lib/Doctrine/Query/ParserResult.php index 6f0ffcf78..85afdaf7e 100755 --- a/lib/Doctrine/Query/ParserResult.php +++ b/lib/Doctrine/Query/ParserResult.php @@ -142,6 +142,12 @@ class Doctrine_Query_ParserResult extends Doctrine_Query_AbstractResult { $baseAlias = strtolower(preg_replace('/[^A-Z]/', '\\1', $componentName)); + // We may have a situation where we have all chars are lowercased + if ( $baseAlias == '' ) { + // We simply grab the first 2 chars of component name + $baseAlias = substr($componentNam, 0, 2); + } + $alias = $baseAlias; if ( ! isset($this->_tableAliasSeeds[$baseAlias])) { diff --git a/lib/Doctrine/Query/Production/RangeVariableDeclaration.php b/lib/Doctrine/Query/Production/RangeVariableDeclaration.php index dd40f9888..4c49cb67a 100644 --- a/lib/Doctrine/Query/Production/RangeVariableDeclaration.php +++ b/lib/Doctrine/Query/Production/RangeVariableDeclaration.php @@ -144,7 +144,7 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_ //echo "Identification Variable: " .$this->_identificationVariable . "\n"; - $tableAlias = $parserResult->generateTableAlias($componentName); + $tableAlias = $parserResult->generateTableAlias($classMetadata->getClassName()); $parserResult->setQueryComponent($this->_identificationVariable, $queryComponent); $parserResult->setTableAlias($tableAlias, $this->_identificationVariable); } @@ -216,7 +216,7 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_ $parent = $path; } catch (Doctrine_Exception $e) { - //echo "Tried to load class metadata from '".$relationName."'\n"; + echo "Tried to load class metadata from '".$relationName."'\n"; $this->_parser->semanticalError($e->getMessage()); return; @@ -228,7 +228,10 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_ $this->_identificationVariable = $path; } - $tableAlias = $parserResult->generateTableAlias($path); + $tableAlias = $parserResult->generateTableAlias($classMetadata->getClassName()); + + //echo "Table alias: " . $tableAlias . "\n"; + $parserResult->setQueryComponent($this->_identificationVariable, $queryComponent); $parserResult->setTableAlias($tableAlias, $this->_identificationVariable); } diff --git a/tests/Orm/Query/SelectSqlGenerationTest.php b/tests/Orm/Query/SelectSqlGenerationTest.php index 687f4cbb6..ac4ea3258 100755 --- a/tests/Orm/Query/SelectSqlGenerationTest.php +++ b/tests/Orm/Query/SelectSqlGenerationTest.php @@ -45,6 +45,7 @@ class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase //echo print_r($query->parse()->getQueryFields(), true) . "\n"; parent::assertEquals($sqlToBeConfirmed, $query->getSql()); + //echo $query->getSql() . "\n"; $query->free(); } catch (Doctrine_Exception $e) { @@ -93,17 +94,15 @@ class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase ); } -/* - Not supported yet! public function testSelectMultipleComponentsWithAsterisk() { $this->assertSqlGeneration( 'SELECT u.*, p.* FROM CmsUser u, u.phonenumbers p', - 'SELECT cu.id AS cu__id, cu.status AS cu__status, cu.username AS cu__username, cu.name AS cu__name FROM cms_user cu WHERE 1 = 1' + 'SELECT cu.id AS cu__id, cu.status AS cu__status, cu.username AS cu__username, cu.name AS cu__name, cp.user_id AS cp__user_id, cp.phonenumber AS cp__phonenumber FROM cms_user cu, cms_phonenumber cp WHERE 1 = 1' ); } -*/ + public function testSelectDistinctIsSupported() {