Commit be5eb98e authored by zYne's avatar zYne

--no commit message

--no commit message
parent 2f70b203
......@@ -388,6 +388,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if ($obj instanceof Doctrine_Record &&
$obj->isModified()) {
$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())
. ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
. ' WHERE ' . implode(' = ? AND ', (array) $record->getTable()->getIdentifier())
. ' = ?';
$stmt = $this->conn->prepare($sql);
......@@ -575,7 +582,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return false;
}
$table = $record->getTable();
$keys = $table->getPrimaryKeys();
$keys = (array) $table->getIdentifier();
$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
// a subquery of another query object
if ( ! $this->isSubquery) {
$fields = array_unique(array_merge($table->getPrimaryKeys(), $fields));
$fields = array_unique(array_merge((array) $table->getIdentifier(), $fields));
}
}
$sql = array();
......@@ -1243,8 +1243,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
case 'by':
continue;
default:
if ( ! isset($p))
if ( ! isset($p)) {
throw new Doctrine_Query_Exception("Couldn't parse query.");
}
$parts[$p][] = $part;
}
......@@ -1267,7 +1268,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if ($clear) {
$this->clear();
}
$query = trim($query);
$query = str_replace("\n", ' ', $query);
$query = str_replace("\r", ' ', $query);
......
......@@ -35,7 +35,5 @@ class Doctrine_Query_Select extends Doctrine_Query_Part
public function parse($dql)
{
$this->query->parseSelect($dql);
return null;
}
}
......@@ -34,19 +34,24 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
{
public function parse($dql)
{
preg_match_all("/[a-z0-9_]+\.[a-z0-9_]+[\.[a-z0-9]+]*/i", $dql, $m);
$terms = Doctrine_Tokenizer::sqlExplode($dql, ' ');
foreach ($terms as $term) {
if (isset($m[0])) {
foreach ($m[0] as $part) {
$e = explode('.', trim($part));
$field = array_pop($e);
preg_match_all("/[a-z0-9_]+\.[a-z0-9_]+[\.[a-z0-9]+]*/i", $term, $m);
$reference = implode('.', $e);
$alias = $this->query->getTableAlias($reference);
$map = $this->query->getAliasDeclaration($reference);
$dql = str_replace($part, $map['table']->getColumnName($field), $dql);
if (isset($m[0])) {
foreach ($m[0] as $part) {
$e = explode('.', trim($part));
$field = array_pop($e);
$reference = implode('.', $e);
$alias = $this->query->getTableAlias($reference);
$map = $this->query->getAliasDeclaration($reference);
$dql = str_replace($part, $map['table']->getColumnName($field), $dql);
}
}
}
......
......@@ -68,7 +68,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$map = $this->query->getRootDeclaration();
$alias = $this->query->getTableAlias($this->query->getRootAlias());
$table = $map['table'];
$table = $map['table'];
} else {
$map = $this->query->load($reference, false);
......@@ -127,6 +127,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$value[] = $this->parseLiteralValue($part);
}
}
$value = '(' . implode(', ', $value) . ')';
}
} elseif (substr($value, 0, 1) == ':' || $value === '?') {
......
......@@ -164,7 +164,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
foreach ($this->getTableAliases() as $tableAlias => $componentAlias) {
$map = $this->_aliasMap[$componentAlias];
foreach ($map['table']->getPrimaryKeys() as $key) {
foreach ((array) $map['table']->getIdentifier() as $key) {
$field = $tableAlias . '.' . $key;
if ( ! isset($this->parts['select'][$field])) {
......
......@@ -148,7 +148,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
self::$_index++;
$keys = $this->_table->getPrimaryKeys();
$keys = (array) $this->_table->getIdentifier();
// get the data array
$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
*/
private $conn;
private $_conn;
/**
* @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)
{
$this->conn = $conn;
$this->_conn = $conn;
$this->setParent($this->conn);
$this->setParent($this->_conn);
$this->options['name'] = $name;
$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) {
$this->options['sequenceName'] = $sequence;
} else {
$this->options['sequenceName'] = $this->conn->getSequenceName($this->options['tableName']);
$this->options['sequenceName'] = $this->_conn->getSequenceName($this->options['tableName']);
}
}
break;
......@@ -315,7 +315,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public function export()
{
$this->conn->export->exportTable($this);
$this->_conn->export->exportTable($this);
}
/**
* getExportableFormat
......@@ -413,14 +413,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
public function exportConstraints()
{
try {
$this->conn->beginTransaction();
$this->_conn->beginTransaction();
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) {
$this->conn->rollback();
$this->_conn->rollback();
throw $e;
}
......@@ -799,42 +799,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
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
*/
public function getConnection()
{
return $this->conn;
return $this->_conn;
}
/**
* create
......@@ -894,7 +864,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
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);
return $users;
}
......@@ -909,7 +879,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @return Doctrine_Collection
*/
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);
return $users;
}
......@@ -1023,7 +993,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
return $this->options['name'];
}
foreach ($this->options['subclasses'] as $subclass) {
$table = $this->conn->getTable($subclass);
$table = $this->_conn->getTable($subclass);
$inheritanceMap = $table->getOption('inheritanceMap');
$nomatch = false;
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']));
$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)
return false;
......@@ -1067,7 +1037,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
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);
}
/**
......@@ -1104,7 +1074,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
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])
) {
return $this->columns[$field]['values'][$index];
......@@ -1124,7 +1094,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$values = $this->getEnumValues($field);
$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 $value;
......
......@@ -57,7 +57,7 @@ class Doctrine_Validator_Unique
// as the one that is validated here.
$state = $this->invoker->state();
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} != ?";
$values[] = $this->invoker->$pk;
}
......
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