Commit 615dcdb8 authored by zYne's avatar zYne

--no commit message

--no commit message
parent ce1002a0
......@@ -31,7 +31,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
abstract class Doctrine_Configurable
abstract class Doctrine_Configurable extends Doctrine_Object
{
/**
* @var array $attributes an array of containing all attributes
......
......@@ -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;
......
......@@ -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
......
......@@ -163,7 +163,6 @@ 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
......
......@@ -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;
......
......@@ -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);
$params = array_merge($id, array_values($this->options['inheritanceMap']));
$stmt = $this->conn->execute($query, $params);
$this->data = $stmt->fetch(PDO::FETCH_ASSOC);
$records = Doctrine_Query::create()
->from($this->getComponentName())
->where(implode(' = ? AND ', $this->primaryKeys) . ' = ?')
->execute($id);
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);
......
......@@ -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() {
......
......@@ -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());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment