From 1c4f4f665b66d2436b39b75863ce4cde1ea1c982 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 9 Jul 2007 12:36:21 +0000 Subject: [PATCH] --- lib/Doctrine/Expression/Driver.php | 2 +- lib/Doctrine/Query.php | 5 +++ tests/Query/ExpressionTestCase.php | 51 ++++++++++++++++++++++++++++++ tests/UnitTestCase.php | 1 - 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Expression/Driver.php b/lib/Doctrine/Expression/Driver.php index 344e516fc..adf5cba2f 100644 --- a/lib/Doctrine/Expression/Driver.php +++ b/lib/Doctrine/Expression/Driver.php @@ -681,6 +681,6 @@ class Doctrine_Expression_Driver extends Doctrine_Connection_Module if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EXPR) { throw new Doctrine_Expression_Exception('Unknown expression ' . $m); } - return $m . '()'; + return $m . '(' . implode(', ', $a) . ')'; } } diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index ce3b51b2d..48c42d606 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -561,6 +561,11 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable // iterate through the component references within the aggregate function if ( ! empty ($components)) { foreach ($components as $component) { + + if (is_numeric($component)) { + continue; + } + $e = explode('.', $component); $field = array_pop($e); diff --git a/tests/Query/ExpressionTestCase.php b/tests/Query/ExpressionTestCase.php index 63da51d40..f174ce0bc 100644 --- a/tests/Query/ExpressionTestCase.php +++ b/tests/Query/ExpressionTestCase.php @@ -87,4 +87,55 @@ class Doctrine_Query_Expression_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(), "SELECT CONCAT(e.name, 'The Man', e.loginname) AS e__0 FROM entity e WHERE (e.type = 0)"); } + + public function testNonPortableFunctionsAreSupported() + { + $query = new Doctrine_Query(); + // we are using stored procedure here, so adjust portability settings + $this->conn->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL ^ Doctrine::PORTABILITY_EXPR); + + $lat = '13.23'; + $lon = '33.23'; + $radius = '33'; + + $query->select("l.*, i18n.*, GeoDistKM(l.lat, l.lon, $lat, $lon) distance") + ->from('Location l, l.LocationI18n i18n') + ->where('l.id <> ? AND i18n.culture = ?', array(1, 'en')) + ->having("distance < $radius") + ->orderby('distance ASC') + ->groupby('l.id') + ->limit(5); + + $this->assertEqual($query->getSql(), "SELECT l.id AS l__id, l.lat AS l__lat, l.lon AS l__lon, l2.name AS l2__name, l2.id AS l2__id, l2.culture AS l2__culture, GeoDistKM(l.lat, l.lon, 13.23, 33.23) AS l__0 FROM location l LEFT JOIN location_i18n l2 ON l.id = l2.id WHERE l.id IN (SELECT DISTINCT l3.id FROM location l3 LEFT JOIN location_i18n l4 ON l3.id = l4.id WHERE (l3.id <> ? AND l4.culture = ?) GROUP BY l3.id HAVING l__0 < 33 ORDER BY l__0 ASC LIMIT 5) AND (l.id <> ? AND l2.culture = ?) GROUP BY l.id HAVING l__0 < 33 ORDER BY l__0 ASC"); + + $this->conn->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL); + } +} +class Location extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('lat', 'double', 10, array ()); + $this->hasColumn('lon', 'double', 10, array ()); + } + + public function setUp() + { + $this->hasMany('LocationI18n as LocationI18n', array('local' => 'id', 'foreign' => 'id')); + } +} + +class LocationI18n extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('name', 'string', 50, array()); + $this->hasColumn('id', 'integer', 10, array('primary' => true)); + $this->hasColumn('culture', 'string', 2); + } + + public function setUp() + { + $this->hasOne('Location as Location', array('local' => 'id')); + } } diff --git a/tests/UnitTestCase.php b/tests/UnitTestCase.php index 8b6b36cfc..0f109759c 100644 --- a/tests/UnitTestCase.php +++ b/tests/UnitTestCase.php @@ -186,7 +186,6 @@ class Doctrine_UnitTestCase extends UnitTestCase } } - $this->conn->export->exportClasses($this->tables); /** foreach($this->tables as $name) {