1
0
mirror of synced 2024-12-13 22:56:04 +03:00
This commit is contained in:
zYne 2007-07-09 11:23:44 +00:00
parent 54e5f45c61
commit 5aea10ec39
5 changed files with 24 additions and 47 deletions

View File

@ -324,7 +324,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
public function getDqlPart($queryPart)
{
if ( ! isset($this->_dqlParts[$queryPart])) {
throw new Doctrine_Query_Exception('Unknown query part ' . $queryPart);
throw new Doctrine_Query_Exception('Unknown query part ' . $queryPart);
}
return $this->_dqlParts[$queryPart];
@ -811,20 +811,19 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
case 'mysql':
// mysql doesn't support LIMIT in subqueries
$list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);
$subquery = $this->inConditionFromArray($list);
$subquery = implode(', ', array_map(array($this->_conn, 'quote'), $list));
break;
case 'pgsql':
// pgsql needs special nested LIMIT subquery
$subquery = ' IN (SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias)';
$subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias';
break;
}
$field = $this->getTableAlias($rootAlias) . '.' . $table->getIdentifier();
// only append the subquery if it actually contains something
if ($subquery !== '')
{
array_unshift($this->parts['where'], $this->_conn->quoteIdentifier($field) . $subquery);
if ($subquery !== '') {
array_unshift($this->parts['where'], $this->_conn->quoteIdentifier($field) . ' IN (' . $subquery . ')');
}
$modifyLimit = false;
@ -1273,41 +1272,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
return $this->_aliasMap[$componentAlias];
}
/**
* inConditionFromArray
*
* explode array into quoted array (quick and dirty)
*
* @param array $values
*
* @return mixed - SQL list of conditions passed, or false if empty
*/
//TODO: check column type instead of first array value?
//TODO: is there cleaner value quoting as part of Doctrine somewhere?
public function inConditionFromArray(array $values)
{
if (empty($values))
return false;
$list_values = ' IN (';
// is first value a string? then assume column is.
if (is_string($values[0]))
{
foreach ($values as &$value)
{
$value = '\'' . $value . '\'';
}
}
$list_values .= implode(', ', $values);
$list_values .= ')';
return $list_values;
}
}
/**
* loadRoot
*

View File

@ -52,7 +52,7 @@ class Doctrine_Query_IdentifierQuoting_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), 'SELECT MAX("e.id") AS "e__0", MIN("e.name") AS "e__1" FROM "entity" "e" WHERE ("e.type" = 0)');
}
public function testQuerySupportsIdentifierQuotingInWherePart()
{
$q = new Doctrine_Query();
@ -62,6 +62,15 @@ class Doctrine_Query_IdentifierQuoting_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), 'SELECT "e.id" AS "e__id", "e.name" AS "e__name" FROM "entity" "e" WHERE "e.id" = 3 AND ("e.type" = 0)');
}
public function testQuerySupportsIdentifierQuotingWorksWithinFunctions()
{
$q = new Doctrine_Query();
$q->parseQuery("SELECT u.name FROM User u WHERE TRIM(u.name) = 'zYne'");
$this->assertEqual($q->getQuery(), 'SELECT "e.id" AS "e__id", "e.name" AS "e__name" FROM "entity" "e" WHERE TRIM(u.name) = 3 AND ("e.type" = 0)');
}
public function testQuerySupportsIdentifierQuotingWithJoins()
{
$q = new Doctrine_Query();

View File

@ -42,7 +42,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
parent::prepareTables();
}
/**
public function testLimitWithOneToOneLeftJoin()
{
$q = new Doctrine_Query();
@ -62,7 +62,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users->count(), 5);
$this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e2.id AS e2__id, e2.address AS e2__address FROM entity e INNER JOIN email e2 ON e.email_id = e2.id WHERE (e.type = 0) LIMIT 5");
}
*/
public function testLimitWithOneToManyLeftJoin()
{
$q = new Doctrine_Query();

View File

@ -243,6 +243,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$q->execute(array('verified'));
}
public function testEnumValuesWorkWithMultiplePlaceholders()
{
$q = new Doctrine_Query();
@ -256,6 +257,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$this->assertTrue(empty($p[0]));
$q->execute(array(1, 'verified'));
}
public function testEnumValuesWorkWithMultipleNamedPlaceholders()
{
$q = new Doctrine_Query();
@ -263,7 +265,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase
$q->select('e.*')->from('EnumTest e')->where('e.id = :id AND e.status = :status');
$q->getQuery();
$p = $q->getEnumParams();
$this->assertEqual(array_keys($p), array(':id', ':status'));
$this->assertTrue(empty($p[':id']));

View File

@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
$test->addTestCase(new Doctrine_Ticket330_TestCase());
*/
/** */
// Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
@ -249,7 +249,7 @@ $test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_Query_IdentifierQuoting_TestCase());
//$test->addTestCase(new Doctrine_Query_IdentifierQuoting_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase());
$test->addTestCase(new Doctrine_Query_Delete_TestCase());