From 615dcdb84e7c0c932eddb0ef7fbf5a4d28dc1292 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 5 Jul 2007 20:03:38 +0000 Subject: [PATCH] --- lib/Doctrine/Configurable.php | 2 +- lib/Doctrine/Hydrate.php | 9 ++++--- lib/Doctrine/Manager.php | 16 +----------- lib/Doctrine/Record.php | 16 ++++++------ lib/Doctrine/Record/Filter.php | 45 +--------------------------------- lib/Doctrine/Table.php | 24 ++++++++---------- tests/EnumTestCase.php | 11 +++++---- tests/run.php | 4 +-- 8 files changed, 35 insertions(+), 92 deletions(-) diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index 9b63a44d9..9673c2d17 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -31,7 +31,7 @@ * @version $Revision$ * @author Konsta Vesterinen */ -abstract class Doctrine_Configurable +abstract class Doctrine_Configurable extends Doctrine_Object { /** * @var array $attributes an array of containing all attributes diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index e8b9ee341..1faa1db72 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -946,7 +946,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable return $array; } - while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { + while ($data = $stmt->fetch(Doctrine::FETCH_ASSOC)) { $parse = true; @@ -965,6 +965,7 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable $map = $this->_aliasMap[$cache[$key]['alias']]; $table = $map['table']; $alias = $cache[$key]['alias']; + $field = $cache[$key]['field']; $componentName = $map['table']->getComponentName(); if (isset($map['relation'])) { @@ -1039,8 +1040,10 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable $currData[$alias] = array(); $identifiable[$alias] = null; } - $field = $cache[$key]['field']; - $currData[$alias][$field] = $value; + + + + $currData[$alias][$field] = $table->prepareValue($field, $value); $index = false; if ($value !== null) { $identifiable[$alias] = true; diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 7c90a20c6..6ecde9186 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -53,10 +53,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera * @var string $root root directory */ protected $_root; - /** - * @var Doctrine_Null $null Doctrine_Null object, used for extremely fast null value checking - */ - protected $_null; /** * @var array $_integrityActions an array containing all registered integrity actions * used when emulating these actions @@ -72,11 +68,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera private function __construct() { $this->_root = dirname(__FILE__); - $this->_null = new Doctrine_Null; - Doctrine_Record_Iterator::initNullObject($this->_null); - Doctrine_Validator::initNullObject($this->_null); - Doctrine_Object::initNullObject($this->_null); + Doctrine_Object::initNullObject(new Doctrine_Null); } public function addDeleteAction($componentName, $foreignComponent, $action) { @@ -102,13 +95,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera return $this->_integrityActions[$componentName]['onUpdate']; } - /** - * @return Doctrine_Null - */ - final public function getNullObject() - { - return $this->_null; - } /** * setDefaultAttributes * sets default attributes diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index b8b4eb9aa..09c96cc8e 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -162,8 +162,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count // get the column count $count = count($this->_data); - - // clean data array + $this->_data = $this->_filter->cleanData($this->_data); $this->prepareIdentifiers($exists); @@ -625,12 +624,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count } $id = array_values($id); - $query = 'SELECT * FROM ' . $this->_table->getOption('tableName') . ' WHERE ' . implode(' = ? AND ', $this->_table->getPrimaryKeys()) . ' = ?'; - $stmt = $this->_table->getConnection()->execute($query,$id); + $records = Doctrine_Query::create() + ->from($this->_table->getComponentName()) + ->where(implode(' = ? AND ', $this->_table->getPrimaryKeys()) . ' = ?') + ->execute($id); - $this->_data = $stmt->fetch(PDO::FETCH_ASSOC); - if ( ! $this->_data) { + if (count($records) === 0) { throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.'); } @@ -645,7 +645,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this); - return true; + return $this; } /** * factoryRefresh @@ -1049,7 +1049,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count default: if ($this->_data[$v] instanceof Doctrine_Record) { $this->_data[$v] = $this->_data[$v]->getIncremented(); - } + } $a[$v] = $this->_data[$v]; } diff --git a/lib/Doctrine/Record/Filter.php b/lib/Doctrine/Record/Filter.php index f86a15f9a..1b6663077 100644 --- a/lib/Doctrine/Record/Filter.php +++ b/lib/Doctrine/Record/Filter.php @@ -111,52 +111,9 @@ class Doctrine_Record_Filter extends Doctrine_Object */ public function cleanData($data) { - $tmp = $data; - $data = array(); - foreach ($this->_record->getTable()->getColumnNames() as $name) { - $type = $this->_record->getTable()->getTypeOf($name); - - if ( ! isset($tmp[$name])) { + if ( ! isset($data[$name])) { $data[$name] = self::$_null; - } else { - switch ($type) { - case 'array': - case 'object': - if ($tmp[$name] !== self::$_null) { - if (is_string($tmp[$name])) { - $value = unserialize($tmp[$name]); - - if ($value === false) { - throw new Doctrine_Record_Exception('Unserialization of ' . $name . ' failed.'); - } - } else { - $value = $tmp[$name]; - } - $data[$name] = $value; - } - break; - case 'gzip': - if ($tmp[$name] !== self::$_null) { - $value = gzuncompress($tmp[$name]); - - if ($value === false) { - throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.'); - } - - $data[$name] = $value; - } - break; - case 'enum': - $data[$name] = $this->_record->getTable()->enumValue($name, $tmp[$name]); - break; - case 'boolean': - $data[$name] = (boolean) $tmp[$name]; - break; - default: - $data[$name] = $tmp[$name]; - } - } } return $data; diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 49f362257..713210538 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -811,20 +811,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable $id = array_values($id); } - $query = 'SELECT ' . implode(', ', array_keys($this->columns)) . ' FROM ' . $this->getTableName() - . ' WHERE ' . implode(' = ? AND ', $this->primaryKeys) . ' = ?'; - $query = $this->applyInheritance($query); + $records = Doctrine_Query::create() + ->from($this->getComponentName()) + ->where(implode(' = ? AND ', $this->primaryKeys) . ' = ?') + ->execute($id); - $params = array_merge($id, array_values($this->options['inheritanceMap'])); - - $stmt = $this->conn->execute($query, $params); - - $this->data = $stmt->fetch(PDO::FETCH_ASSOC); - - if ($this->data === false) + if (count($records) === 0) { return false; + } - return $this->getRecord(); + return $records->getFirst(); } return false; } @@ -967,7 +963,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable $inheritanceMap = $table->getOption('inheritanceMap'); $nomatch = false; foreach ($inheritanceMap as $key => $value) { - if (!isset($this->data[$key]) || $this->data[$key] != $value) { + if ( ! isset($this->data[$key]) || $this->data[$key] !== $value) { $nomatch = true; break; } @@ -1178,7 +1174,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable */ public function prepareValue($field, $value) { - if ($value === null) { + if ($value === null || $value === self::$_null) { return self::$_null; } else { $type = $this->getTypeOf($field); @@ -1211,7 +1207,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable break; case 'integer': return (int) $value; - break; + break; } } return $value; diff --git a/tests/EnumTestCase.php b/tests/EnumTestCase.php index ce6cf5457..25f9c1e03 100644 --- a/tests/EnumTestCase.php +++ b/tests/EnumTestCase.php @@ -39,7 +39,7 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase $this->tables = array("EnumTest", "EnumTest2", "EnumTest3"); parent::prepareTables(); } - /** + public function testParameterConversion() { $test = new EnumTest(); @@ -97,6 +97,7 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase $this->fail(); } } + public function testNotEqual() { try { @@ -107,7 +108,7 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase $this->fail(); } } - */ + public function testEnumType() { @@ -164,13 +165,13 @@ class Doctrine_Enum_TestCase extends Doctrine_UnitTestCase $this->conn->exec('DELETE FROM enum_test WHERE id = 1'); - $f = false; try { $enum->refresh(); + + $this->fail(); } catch(Doctrine_Record_Exception $e) { - $f = true; + $this->pass(); } - $this->assertTrue($f); } public function testEnumFetchArray() { diff --git a/tests/run.php b/tests/run.php index 7ca21c154..1ea52707d 100644 --- a/tests/run.php +++ b/tests/run.php @@ -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()); @@ -182,7 +182,6 @@ $test->addTestCase(new Doctrine_Relation_Parser_TestCase()); // Datatypes $test->addTestCase(new Doctrine_Enum_TestCase()); - $test->addTestCase(new Doctrine_Boolean_TestCase()); // Utility components @@ -190,6 +189,7 @@ $test->addTestCase(new Doctrine_Boolean_TestCase()); //$test->addTestCase(new Doctrine_PessimisticLocking_TestCase()); + $test->addTestCase(new Doctrine_View_TestCase()); $test->addTestCase(new Doctrine_Validator_TestCase());