Details
Description
Hi Jon
I ran into and patched another bug in Doctrine 1.2.2 (The menu in jija shows 1.2.3 as released but I am not seeing it in SVN or on the web site so I can't test the bug in that version).
When you include a dot in a string in your select statement the function getExpressionOwner in Doctrine_Query fires and considers that the text appearing before the dot in the string is the name of a class. There for it attempts to extract a short alias out of it.
I made a test case to illustrate this:
public function testQuoteEncapedDots() { $q = new Doctrine_Query(); $q->select("'testing.dots.inquotes' as string, u.name")->from('User u'); $this->assertEqual($q->getSqlQuery(), "SELECT e.id AS e__id, e.name AS e__name, 'testing.dots.inquotes' AS e__0 FROM entity e WHERE (e.type = 0)"); }
It throws the following exception.
Unexpected Doctrine_Query_Exception thrown in [Doctrine_Query_ShortAliases_TestC ase] with message [Couldn't get short alias for testing] in C:\htdocs\php_librar y\Doctrine_1.2_SVN\lib\Doctrine\Query\Abstract.php on line 679 Trace ------------- #0 C:\htdocs\php_library\Doctrine_1.2_SVN\lib\Doctrine\Query.php(641): Doctrine_ Query_Abstract->getSqlTableAlias('testing') #1 C:\htdocs\php_library\Doctrine_1.2_SVN\lib\Doctrine\Query\Select.php(37): Doc trine_Query->parseSelect(''testing.dots.i...') #2 C:\htdocs\php_library\Doctrine_1.2_SVN\lib\Doctrine\Query\Abstract.php(2083): Doctrine_Query_Select->parse(''testing.dots.i...') #3 C:\htdocs\php_library\Doctrine_1.2_SVN\lib\Doctrine\Query.php(1168): Doctrine _Query_Abstract->_processDqlQueryPart('select', Array) #4 C:\htdocs\php_library\Doctrine_1.2_SVN\lib\Doctrine\Query.php(1134): Doctrine _Query->buildSqlQuery(true) #5 C:\htdocs\php_library\Doctrine_1.2_SVN\tests\Query\ShortAliasesTestCase.php(3 0): Doctrine_Query->getSqlQuery() #6 C:\htdocs\php_library\Doctrine_1.2_SVN\tests\DoctrineTest\UnitTestCase.php(15 8): Doctrine_Query_ShortAliases_TestCase->testQuoteEncapedDots() #7 C:\htdocs\php_library\Doctrine_1.2_SVN\tests\DoctrineTest\GroupTest.php(75): UnitTestCase->run() #8 C:\htdocs\php_library\Doctrine_1.2_SVN\tests\DoctrineTest.php(183): GroupTest ->run(Object(DoctrineTest_Reporter_Cli), Array) #9 C:\htdocs\php_library\Doctrine_1.2_SVN\tests\run.php(320): DoctrineTest->run( ) #10 {main}
I patched the bug by doing a preg_replace where all quote encaped strings are removed before looking for the short alias. The getExpressionOwner function now reads as follows in my code:
public function getExpressionOwner($expr) { if (strtoupper(substr(trim($expr, '( '), 0, 6)) !== 'SELECT') { $expr = preg_replace('/([\\]*[\'\"])[^\1]*\1/', '', $expr); preg_match_all("/[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*[\.[a-z0-9]+]*/i", $expr, $matches); $match = current($matches); if (isset($match[0])) { $terms = explode('.', $match[0]); return $terms[0]; } } return $this->getRootAlias(); }
I am including the patch with this post but I think my version of the code base is starting diverge as I also have a few other things added to mine (as discussed in: DC-701)
Hope you are well.
Will Ferrer