fixes #310
This commit is contained in:
parent
b81f399c12
commit
7a9a86a5c6
@ -42,6 +42,10 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
|
|||||||
{
|
{
|
||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
$this->stmt = $stmt;
|
$this->stmt = $stmt;
|
||||||
|
|
||||||
|
if ($stmt === false) {
|
||||||
|
throw new Doctrine_Db_Exception('Unknown statement object given.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -382,7 +382,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
*
|
*
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
private function cleanData($debug = false)
|
private function cleanData()
|
||||||
{
|
{
|
||||||
$tmp = $this->_data;
|
$tmp = $this->_data;
|
||||||
|
|
||||||
@ -397,42 +397,57 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
$this->_data[$name] = self::$null;
|
$this->_data[$name] = self::$null;
|
||||||
} else {
|
} else {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case "array":
|
case 'array':
|
||||||
case "object":
|
case 'object':
|
||||||
if ($tmp[$name] !== self::$null) {
|
if ($tmp[$name] !== self::$null) {
|
||||||
if (is_string($tmp[$name])) {
|
if (is_string($tmp[$name])) {
|
||||||
$value = unserialize($tmp[$name]);
|
$value = unserialize($tmp[$name]);
|
||||||
|
|
||||||
if ($value === false)
|
if ($value === false)
|
||||||
throw new Doctrine_Record_Exception("Unserialization of $name failed.");
|
throw new Doctrine_Record_Exception('Unserialization of ' . $name . ' failed.');
|
||||||
} else {
|
} else {
|
||||||
$value = $tmp[$name];
|
$value = $tmp[$name];
|
||||||
}
|
}
|
||||||
$this->_data[$name] = $value;
|
$this->_data[$name] = $value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "gzip":
|
case 'gzip':
|
||||||
if ($tmp[$name] !== self::$null) {
|
if ($tmp[$name] !== self::$null) {
|
||||||
$value = gzuncompress($tmp[$name]);
|
$value = gzuncompress($tmp[$name]);
|
||||||
|
|
||||||
if ($value === false)
|
if ($value === false)
|
||||||
throw new Doctrine_Record_Exception("Uncompressing of $name failed.");
|
throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.');
|
||||||
|
|
||||||
$this->_data[$name] = $value;
|
$this->_data[$name] = $value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "enum":
|
case 'enum':
|
||||||
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
|
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->_data[$name] = $tmp[$name];
|
$this->_data[$name] = $tmp[$name];
|
||||||
};
|
}
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* hydrate
|
||||||
|
* hydrates this object from given array
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function hydrate(array $data)
|
||||||
|
{
|
||||||
|
foreach ($data as $k => $v) {
|
||||||
|
$this->_data[$k] = $v;
|
||||||
|
}
|
||||||
|
$this->cleanData();
|
||||||
|
$this->prepareIdentifiers();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* prepareIdentifiers
|
* prepareIdentifiers
|
||||||
* prepares identifiers for later use
|
* prepares identifiers for later use
|
||||||
|
@ -1144,6 +1144,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
|
|
||||||
if (isset($this->identityMap[$id])) {
|
if (isset($this->identityMap[$id])) {
|
||||||
$record = $this->identityMap[$id];
|
$record = $this->identityMap[$id];
|
||||||
|
$record->hydrate($this->data);
|
||||||
} else {
|
} else {
|
||||||
$recordName = $this->getClassnameToReturn();
|
$recordName = $this->getClassnameToReturn();
|
||||||
$record = new $recordName($this);
|
$record = new $recordName($this);
|
||||||
@ -1183,7 +1184,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$nomatch) {
|
if ( ! $nomatch) {
|
||||||
return $table->getComponentName();
|
return $table->getComponentName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,4 +107,27 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase {
|
|||||||
|
|
||||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
||||||
}
|
}
|
||||||
|
public function testProxiesAreAutomaticallyUpdatedWithFetches()
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$user->name = 'someuser';
|
||||||
|
$user->password = '123';
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$this->connection->clear();
|
||||||
|
|
||||||
|
$user = $this->connection->queryOne("SELECT u.name FROM User u WHERE u.name = 'someuser'");
|
||||||
|
|
||||||
|
$this->assertEqual($user->state(), Doctrine_Record::STATE_PROXY);
|
||||||
|
|
||||||
|
$user2 = $this->connection->queryOne("FROM User u WHERE u.name = 'someuser'");
|
||||||
|
|
||||||
|
$this->assertEqual($user->getOID(), $user2->getOID());
|
||||||
|
|
||||||
|
$count = count($this->dbh);
|
||||||
|
|
||||||
|
$this->assertEqual($user->password, '123');
|
||||||
|
|
||||||
|
$this->assertEqual($count, count($this->dbh));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user