rawSql parser fixed
This commit is contained in:
parent
5059dbc90d
commit
38a4a23c5e
@ -501,7 +501,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
|
|||||||
* @param string $e2 the second bracket, usually ')'
|
* @param string $e2 the second bracket, usually ')'
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function bracketExplode($str,$d,$e1,$e2) {
|
public static function bracketExplode($str,$d,$e1 = '(',$e2 = ')') {
|
||||||
$str = explode("$d",$str);
|
$str = explode("$d",$str);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$term = array();
|
$term = array();
|
||||||
|
@ -53,7 +53,15 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* get
|
||||||
|
*/
|
||||||
|
public function get($name) {
|
||||||
|
if( ! isset($this->parts[$name]))
|
||||||
|
throw new Doctrine_Exception('Unknown query part '.$name);
|
||||||
|
|
||||||
|
return $this->parts[$name];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* parseQuery
|
* parseQuery
|
||||||
*
|
*
|
||||||
@ -66,7 +74,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
$this->fields = $m[1];
|
$this->fields = $m[1];
|
||||||
$this->clear();
|
$this->clear();
|
||||||
|
|
||||||
$e = explode(" ", $query);
|
$e = Doctrine_Query::bracketExplode($query,' ');
|
||||||
|
|
||||||
foreach($e as $k => $part):
|
foreach($e as $k => $part):
|
||||||
$low = strtolower($part);
|
$low = strtolower($part);
|
||||||
@ -78,7 +86,10 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
case "offset":
|
case "offset":
|
||||||
case "having":
|
case "having":
|
||||||
$p = $low;
|
$p = $low;
|
||||||
|
if( ! isset($parts[$low]))
|
||||||
$parts[$low] = array();
|
$parts[$low] = array();
|
||||||
|
else
|
||||||
|
$count[$low]++;
|
||||||
break;
|
break;
|
||||||
case "order":
|
case "order":
|
||||||
case "group":
|
case "group":
|
||||||
@ -92,7 +103,10 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
case "by":
|
case "by":
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
$parts[$p][] = $part;
|
if( ! isset($parts[$p][0]))
|
||||||
|
$parts[$p][0] = $part;
|
||||||
|
else
|
||||||
|
$parts[$p][0] .= ' '.$part;
|
||||||
endswitch;
|
endswitch;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
@ -1,5 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
||||||
|
public function testQueryParser() {
|
||||||
|
$sql = "SELECT {p.*} FROM photos p";
|
||||||
|
$query = new Doctrine_RawSql($this->session);
|
||||||
|
$query->parseQuery($sql);
|
||||||
|
|
||||||
|
$this->assertEqual($query->from, array('photos p'));
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT {p.*} FROM (SELECT p.* FROM photos p LEFT JOIN photos_tags t ON t.photo_id = p.id WHERE t.tag_id = 65) p LEFT JOIN photos_tags t ON t.photo_id = p.id WHERE p.can_see = -1 AND t.tag_id = 62 LIMIT 200";
|
||||||
|
$query->parseQuery($sql);
|
||||||
|
|
||||||
|
$this->assertEqual($query->from, array("(SELECT p.* FROM photos p LEFT JOIN photos_tags t ON t.photo_id = p.id WHERE t.tag_id = 65) p LEFT JOIN photos_tags t ON t.photo_id = p.id"));
|
||||||
|
$this->assertEqual($query->limit, array(200));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAsteriskOperator() {
|
public function testAsteriskOperator() {
|
||||||
// Selecting with *
|
// Selecting with *
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ require_once("QueryLimitTestCase.php");
|
|||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||||
|
/**
|
||||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_SessionTestCase());
|
$test->addTestCase(new Doctrine_SessionTestCase());
|
||||||
@ -53,8 +53,6 @@ $test->addTestCase(new Doctrine_ViewTestCase());
|
|||||||
|
|
||||||
$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
|
$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_RawSql_TestCase());
|
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase());
|
$test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_Filter_TestCase());
|
$test->addTestCase(new Doctrine_Filter_TestCase());
|
||||||
@ -68,7 +66,8 @@ $test->addTestCase(new Doctrine_CollectionTestCase());
|
|||||||
$test->addTestCase(new Doctrine_QueryTestCase());
|
$test->addTestCase(new Doctrine_QueryTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
|
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
|
||||||
|
*/
|
||||||
|
$test->addTestCase(new Doctrine_RawSql_TestCase());
|
||||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user