This commit is contained in:
parent
2f70b203e6
commit
be5eb98ebf
@ -388,6 +388,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
|||||||
if ($obj instanceof Doctrine_Record &&
|
if ($obj instanceof Doctrine_Record &&
|
||||||
$obj->isModified()) {
|
$obj->isModified()) {
|
||||||
$obj->save($this->conn);
|
$obj->save($this->conn);
|
||||||
|
/**
|
||||||
|
$id = array_values($obj->identifier());
|
||||||
|
|
||||||
|
foreach ((array) $rel->getLocal() as $k => $field) {
|
||||||
|
$record->set($field, $id[$k]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,7 +545,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
|||||||
|
|
||||||
$sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName())
|
$sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName())
|
||||||
. ' SET ' . implode(', ', $set)
|
. ' SET ' . implode(', ', $set)
|
||||||
. ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
|
. ' WHERE ' . implode(' = ? AND ', (array) $record->getTable()->getIdentifier())
|
||||||
. ' = ?';
|
. ' = ?';
|
||||||
|
|
||||||
$stmt = $this->conn->prepare($sql);
|
$stmt = $this->conn->prepare($sql);
|
||||||
@ -575,7 +582,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$table = $record->getTable();
|
$table = $record->getTable();
|
||||||
$keys = $table->getPrimaryKeys();
|
$keys = (array) $table->getIdentifier();
|
||||||
|
|
||||||
$seq = $record->getTable()->sequenceName;
|
$seq = $record->getTable()->sequenceName;
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
// only auto-add the primary key fields if this query object is not
|
// only auto-add the primary key fields if this query object is not
|
||||||
// a subquery of another query object
|
// a subquery of another query object
|
||||||
if ( ! $this->isSubquery) {
|
if ( ! $this->isSubquery) {
|
||||||
$fields = array_unique(array_merge($table->getPrimaryKeys(), $fields));
|
$fields = array_unique(array_merge((array) $table->getIdentifier(), $fields));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql = array();
|
$sql = array();
|
||||||
@ -1243,8 +1243,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
case 'by':
|
case 'by':
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
if ( ! isset($p))
|
if ( ! isset($p)) {
|
||||||
throw new Doctrine_Query_Exception("Couldn't parse query.");
|
throw new Doctrine_Query_Exception("Couldn't parse query.");
|
||||||
|
}
|
||||||
|
|
||||||
$parts[$p][] = $part;
|
$parts[$p][] = $part;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,5 @@ class Doctrine_Query_Select extends Doctrine_Query_Part
|
|||||||
public function parse($dql)
|
public function parse($dql)
|
||||||
{
|
{
|
||||||
$this->query->parseSelect($dql);
|
$this->query->parseSelect($dql);
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,24 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
|
|||||||
{
|
{
|
||||||
public function parse($dql)
|
public function parse($dql)
|
||||||
{
|
{
|
||||||
preg_match_all("/[a-z0-9_]+\.[a-z0-9_]+[\.[a-z0-9]+]*/i", $dql, $m);
|
$terms = Doctrine_Tokenizer::sqlExplode($dql, ' ');
|
||||||
|
|
||||||
if (isset($m[0])) {
|
foreach ($terms as $term) {
|
||||||
foreach ($m[0] as $part) {
|
|
||||||
$e = explode('.', trim($part));
|
|
||||||
$field = array_pop($e);
|
|
||||||
|
|
||||||
$reference = implode('.', $e);
|
preg_match_all("/[a-z0-9_]+\.[a-z0-9_]+[\.[a-z0-9]+]*/i", $term, $m);
|
||||||
|
|
||||||
$alias = $this->query->getTableAlias($reference);
|
if (isset($m[0])) {
|
||||||
$map = $this->query->getAliasDeclaration($reference);
|
foreach ($m[0] as $part) {
|
||||||
|
$e = explode('.', trim($part));
|
||||||
|
$field = array_pop($e);
|
||||||
|
|
||||||
$dql = str_replace($part, $map['table']->getColumnName($field), $dql);
|
$reference = implode('.', $e);
|
||||||
|
|
||||||
|
$alias = $this->query->getTableAlias($reference);
|
||||||
|
$map = $this->query->getAliasDeclaration($reference);
|
||||||
|
|
||||||
|
$dql = str_replace($part, $map['table']->getColumnName($field), $dql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
|
|||||||
$value[] = $this->parseLiteralValue($part);
|
$value[] = $this->parseLiteralValue($part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = '(' . implode(', ', $value) . ')';
|
$value = '(' . implode(', ', $value) . ')';
|
||||||
}
|
}
|
||||||
} elseif (substr($value, 0, 1) == ':' || $value === '?') {
|
} elseif (substr($value, 0, 1) == ':' || $value === '?') {
|
||||||
|
@ -164,7 +164,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
|
|||||||
foreach ($this->getTableAliases() as $tableAlias => $componentAlias) {
|
foreach ($this->getTableAliases() as $tableAlias => $componentAlias) {
|
||||||
$map = $this->_aliasMap[$componentAlias];
|
$map = $this->_aliasMap[$componentAlias];
|
||||||
|
|
||||||
foreach ($map['table']->getPrimaryKeys() as $key) {
|
foreach ((array) $map['table']->getIdentifier() as $key) {
|
||||||
$field = $tableAlias . '.' . $key;
|
$field = $tableAlias . '.' . $key;
|
||||||
|
|
||||||
if ( ! isset($this->parts['select'][$field])) {
|
if ( ! isset($this->parts['select'][$field])) {
|
||||||
|
@ -148,7 +148,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
|||||||
|
|
||||||
self::$_index++;
|
self::$_index++;
|
||||||
|
|
||||||
$keys = $this->_table->getPrimaryKeys();
|
$keys = (array) $this->_table->getIdentifier();
|
||||||
|
|
||||||
// get the data array
|
// get the data array
|
||||||
$this->_data = $this->_table->getData();
|
$this->_data = $this->_table->getData();
|
||||||
|
@ -53,7 +53,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
/**
|
/**
|
||||||
* @var Doctrine_Connection $conn Doctrine_Connection object that created this table
|
* @var Doctrine_Connection $conn Doctrine_Connection object that created this table
|
||||||
*/
|
*/
|
||||||
private $conn;
|
private $_conn;
|
||||||
/**
|
/**
|
||||||
* @var array $identityMap first level cache
|
* @var array $identityMap first level cache
|
||||||
*/
|
*/
|
||||||
@ -169,9 +169,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function __construct($name, Doctrine_Connection $conn)
|
public function __construct($name, Doctrine_Connection $conn)
|
||||||
{
|
{
|
||||||
$this->conn = $conn;
|
$this->_conn = $conn;
|
||||||
|
|
||||||
$this->setParent($this->conn);
|
$this->setParent($this->_conn);
|
||||||
|
|
||||||
$this->options['name'] = $name;
|
$this->options['name'] = $name;
|
||||||
$this->_parser = new Doctrine_Relation_Parser($this);
|
$this->_parser = new Doctrine_Relation_Parser($this);
|
||||||
@ -271,7 +271,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
if (($sequence = $this->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
|
if (($sequence = $this->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
|
||||||
$this->options['sequenceName'] = $sequence;
|
$this->options['sequenceName'] = $sequence;
|
||||||
} else {
|
} else {
|
||||||
$this->options['sequenceName'] = $this->conn->getSequenceName($this->options['tableName']);
|
$this->options['sequenceName'] = $this->_conn->getSequenceName($this->options['tableName']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -315,7 +315,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function export()
|
public function export()
|
||||||
{
|
{
|
||||||
$this->conn->export->exportTable($this);
|
$this->_conn->export->exportTable($this);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* getExportableFormat
|
* getExportableFormat
|
||||||
@ -413,14 +413,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
public function exportConstraints()
|
public function exportConstraints()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->conn->beginTransaction();
|
$this->_conn->beginTransaction();
|
||||||
|
|
||||||
foreach ($this->options['index'] as $index => $definition) {
|
foreach ($this->options['index'] as $index => $definition) {
|
||||||
$this->conn->export->createIndex($this->options['tableName'], $index, $definition);
|
$this->_conn->export->createIndex($this->options['tableName'], $index, $definition);
|
||||||
}
|
}
|
||||||
$this->conn->commit();
|
$this->_conn->commit();
|
||||||
} catch(Doctrine_Connection_Exception $e) {
|
} catch(Doctrine_Connection_Exception $e) {
|
||||||
$this->conn->rollback();
|
$this->_conn->rollback();
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
@ -799,42 +799,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
{
|
{
|
||||||
return isset($this->columns[$name]);
|
return isset($this->columns[$name]);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param mixed $key
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setPrimaryKey($key)
|
|
||||||
{
|
|
||||||
switch (gettype($key)) {
|
|
||||||
case "array":
|
|
||||||
$this->primaryKeys = array_values($key);
|
|
||||||
break;
|
|
||||||
case "string":
|
|
||||||
$this->primaryKeys[] = $key;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns all primary keys
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPrimaryKeys()
|
|
||||||
{
|
|
||||||
return $this->primaryKeys;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function hasPrimaryKey($key)
|
|
||||||
{
|
|
||||||
return in_array($key, $this->primaryKeys);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @return Doctrine_Connection
|
* @return Doctrine_Connection
|
||||||
*/
|
*/
|
||||||
public function getConnection()
|
public function getConnection()
|
||||||
{
|
{
|
||||||
return $this->conn;
|
return $this->_conn;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* create
|
* create
|
||||||
@ -894,7 +864,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function findAll($hydrationMode = null)
|
public function findAll($hydrationMode = null)
|
||||||
{
|
{
|
||||||
$graph = new Doctrine_Query($this->conn);
|
$graph = new Doctrine_Query($this->_conn);
|
||||||
$users = $graph->query('FROM ' . $this->options['name'], array(), $hydrationMode);
|
$users = $graph->query('FROM ' . $this->options['name'], array(), $hydrationMode);
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
@ -909,7 +879,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
* @return Doctrine_Collection
|
* @return Doctrine_Collection
|
||||||
*/
|
*/
|
||||||
public function findBySql($dql, array $params = array(), $hydrationMode = null) {
|
public function findBySql($dql, array $params = array(), $hydrationMode = null) {
|
||||||
$q = new Doctrine_Query($this->conn);
|
$q = new Doctrine_Query($this->_conn);
|
||||||
$users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params, $hydrationMode);
|
$users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params, $hydrationMode);
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
@ -1023,7 +993,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
return $this->options['name'];
|
return $this->options['name'];
|
||||||
}
|
}
|
||||||
foreach ($this->options['subclasses'] as $subclass) {
|
foreach ($this->options['subclasses'] as $subclass) {
|
||||||
$table = $this->conn->getTable($subclass);
|
$table = $this->_conn->getTable($subclass);
|
||||||
$inheritanceMap = $table->getOption('inheritanceMap');
|
$inheritanceMap = $table->getOption('inheritanceMap');
|
||||||
$nomatch = false;
|
$nomatch = false;
|
||||||
foreach ($inheritanceMap as $key => $value) {
|
foreach ($inheritanceMap as $key => $value) {
|
||||||
@ -1053,7 +1023,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
|
|
||||||
$params = array_merge(array($id), array_values($this->options['inheritanceMap']));
|
$params = array_merge(array($id), array_values($this->options['inheritanceMap']));
|
||||||
|
|
||||||
$this->data = $this->conn->execute($query, $params)->fetch(PDO::FETCH_ASSOC);
|
$this->data = $this->_conn->execute($query, $params)->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($this->data === false)
|
if ($this->data === false)
|
||||||
return false;
|
return false;
|
||||||
@ -1067,7 +1037,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
$a = $this->conn->execute('SELECT COUNT(1) FROM ' . $this->options['tableName'])->fetch(Doctrine::FETCH_NUM);
|
$a = $this->_conn->execute('SELECT COUNT(1) FROM ' . $this->options['tableName'])->fetch(Doctrine::FETCH_NUM);
|
||||||
return current($a);
|
return current($a);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1104,7 +1074,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
return $index;
|
return $index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)
|
if (!$this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)
|
||||||
&& isset($this->columns[$field]['values'][$index])
|
&& isset($this->columns[$field]['values'][$index])
|
||||||
) {
|
) {
|
||||||
return $this->columns[$field]['values'][$index];
|
return $this->columns[$field]['values'][$index];
|
||||||
@ -1124,7 +1094,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
$values = $this->getEnumValues($field);
|
$values = $this->getEnumValues($field);
|
||||||
|
|
||||||
$index = array_search($value, $values);
|
$index = array_search($value, $values);
|
||||||
if ($index === false || !$this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
if ($index === false || !$this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
||||||
return $index;
|
return $index;
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -57,7 +57,7 @@ class Doctrine_Validator_Unique
|
|||||||
// as the one that is validated here.
|
// as the one that is validated here.
|
||||||
$state = $this->invoker->state();
|
$state = $this->invoker->state();
|
||||||
if ( ! ($state == Doctrine_Record::STATE_TDIRTY || $state == Doctrine_Record::STATE_TCLEAN)) {
|
if ( ! ($state == Doctrine_Record::STATE_TDIRTY || $state == Doctrine_Record::STATE_TCLEAN)) {
|
||||||
foreach ($table->getPrimaryKeys() as $pk) {
|
foreach ((array) $table->getIdentifier() as $pk) {
|
||||||
$sql .= " AND {$pk} != ?";
|
$sql .= " AND {$pk} != ?";
|
||||||
$values[] = $this->invoker->$pk;
|
$values[] = $this->invoker->$pk;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user