1
0
mirror of synced 2024-12-13 06:46:03 +03:00

DQL enum type support (still not working for prepared queries)

This commit is contained in:
zYne 2006-09-13 20:47:29 +00:00
parent 0cbc7031ce
commit 871f3c418d
7 changed files with 90 additions and 9 deletions

View File

@ -30,7 +30,21 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$table = $this->query->load($reference, false);
$where = $this->query->getTableAlias($reference).".".$field." ".$operator." ".$value;
switch($operator) {
case '=':
$alias = $this->query->getTableAlias($reference);
$table = $this->query->getTable($alias);
$enumIndex = $table->enumIndex($field, trim($value,"'"));
if($enumIndex !== false)
$value = $enumIndex;
$where = $alias.'.'.$field.' '.$operator.' '.$value;
break;
default:
$where = $this->query->getTableAlias($reference).'.'.$field.' '.$operator.' '.$value;
}
}
return $where;
}

View File

@ -903,8 +903,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* enumIndex
*/
final public function enumIndex($field, $value) {
$v = array_search($value, $this->enum[$field]);
return $v;
if( ! isset($this->enum[$field]))
$values = array();
else
$values = $this->enum[$field];
return array_search($value, $values);
}
/**
* @return integer

View File

@ -258,6 +258,7 @@ class Doctrine_Validator_Country {
* @return boolean
*/
public function validate(Doctrine_Record $record, $key, $value, $args) {
$value = srttolower($value);
return isset(self::$countries[$value]);
}

View File

@ -5,6 +5,31 @@ class Doctrine_AccessTestCase extends Doctrine_UnitTestCase {
$this->tables = array("Entity", "User");
parent::prepareTables();
}
public function testUnset() {
}
public function testIsset() {
$user = new User();
$this->assertTrue(isset($user->name));
$this->assertFalse(isset($user->unknown));
$this->assertTrue(isset($user['name']));
$this->assertFalse(isset($user['unknown']));
$coll = new Doctrine_Collection('User');
$this->assertFalse(isset($coll[0]));
// test repeated call
$this->assertFalse(isset($coll[0]));
$coll[0];
$this->assertTrue(isset($coll[0]));
// test repeated call
$this->assertTrue(isset($coll[0]));
}
public function testOffsetMethods() {
$user = new User();
$this->assertEqual($user["name"],null);

View File

@ -10,6 +10,11 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "ORM_TestItem";
$this->tables[] = "Log_Status";
$this->tables[] = "Log_Entry";
$this->tables[] = "EnumTest";
$this->tables[] = "Task";
$this->tables[] = "Resource";
$this->tables[] = "ResourceType";
try {
$this->dbh->query("DROP TABLE test_items");
@ -22,8 +27,39 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
}
parent::prepareTables();
$this->connection->clear();
}
public function testEnumConversion() {
$e[0] = new EnumTest();
$e[0]->status = 'open';
$e[1] = new EnumTest();
$e[1]->status = 'verified';
$this->connection->flush();
$this->assertEqual($e[0]->id, 1);
$this->assertEqual($e[1]->id, 2);
$q = new Doctrine_Query;
$coll = $q->from('EnumTest')
->where("EnumTest.status = 'open'")
->execute();
$this->assertEqual($q->getQuery(), 'SELECT enum_test.id AS enum_test__id, enum_test.status AS enum_test__status FROM enum_test WHERE enum_test.status = 0');
$this->assertEqual($coll->count(), 1);
$q = new Doctrine_Query;
$coll = $q->from('EnumTest')
->where("EnumTest.status = 'verified'")
->execute();
$this->assertEqual($q->getQuery(), 'SELECT enum_test.id AS enum_test__id, enum_test.status AS enum_test__status FROM enum_test WHERE enum_test.status = 1');
$this->assertEqual($coll->count(), 1);
}
public function testManyToManyFetchingWithColumnAggregationInheritance() {
$query = new Doctrine_Query($this->connection);

View File

@ -84,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
}
public function prepareTables() {
foreach($this->tables as $name) {
$query = "DROP TABLE ".strtolower($name);
$query = "DROP TABLE ".Doctrine::tableize($name);
try {
$this->dbh->query($query);
} catch(PDOException $e) {

View File

@ -32,6 +32,8 @@ error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_RecordTestCase());
@ -42,8 +44,6 @@ $test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase());
@ -70,11 +70,12 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ImportTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase());