Commit d645b165 authored by romanb's avatar romanb

More refactorings

parent 477199b0
......@@ -1095,6 +1095,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return $this->getTable($name)->create();
}
/**
* Creates a new Doctrine_Query object that operates on this connection.
*
* @return Doctrine_Query
*/
public function createQuery()
{
return new Doctrine_Query($this);
}
/**
* flush
* saves all the records from all tables
......
......@@ -32,7 +32,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializable
abstract class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializable
{
/**
* QUERY TYPE CONSTANTS
......@@ -1284,4 +1284,6 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
{
return $this->parts;
}
abstract public function getQuery($params = array());
}
......@@ -450,13 +450,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$tableAlias = $this->getTableAlias($componentAlias);
$table = $this->_aliasMap[$componentAlias]['table'];
if (isset($this->_pendingFields[$componentAlias])) {
if ( ! isset($this->_pendingFields[$componentAlias])) {
return;
}
$fields = $this->_pendingFields[$componentAlias];
// check for wildcards
if (in_array('*', $fields)) {
//echo "<br />";Doctrine::dump($table->getColumnNames()); echo "<br />";
$fields = $table->getColumnNames();
$fields = $table->getFieldNames();
} else {
// only auto-add the primary key fields if this query object is not
// a subquery of another query object
......@@ -464,28 +467,29 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$fields = array_unique(array_merge((array) $table->getIdentifier(), $fields));
}
}
$sql = array();
foreach ($fields as $name) {
if (($owner = $table->getColumnOwner($name)) !== null &&
foreach ($fields as $fieldName) {
$columnName = $table->getColumnName($fieldName);
if (($owner = $table->getColumnOwner($columnName)) !== null &&
$owner !== $table->getComponentName()) {
$parent = $this->_conn->getTable($owner);
$name = $parent->getColumnName($name);
$columnName = $parent->getColumnName($fieldName);
$parentAlias = $this->getTableAlias($componentAlias . '.' . $parent->getComponentName());
$sql[] = $this->_conn->quoteIdentifier($parentAlias . '.' . $name)
$sql[] = $this->_conn->quoteIdentifier($parentAlias . '.' . $columnName)
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $name);
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
} else {
$name = $table->getColumnName($name);
$columnName = $table->getColumnName($fieldName);
$sql[] = $this->_conn->quoteIdentifier($tableAlias . '.' . $name)
$sql[] = $this->_conn->quoteIdentifier($tableAlias . '.' . $columnName)
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $name);
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
}
}
......@@ -494,7 +498,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
//echo "<br /><br />";
return implode(', ', $sql);
}
}
/**
* parseSelectField
......@@ -1126,8 +1129,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
return $this->_sql;
}
$parts = $this->_dqlParts;
// reset the state
if ( ! $this->isSubquery()) {
$this->_aliasMap = array();
......@@ -1140,6 +1141,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
foreach ($this->_dqlParts as $queryPartName => $queryParts) {
$this->processQueryPart($queryPartName, $queryParts);
}
$params = $this->convertEnums($params);
$this->_state = self::STATE_DIRECT;
......@@ -1148,8 +1150,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->preQuery();
$this->_state = self::STATE_CLEAN;
$this->_dqlParts = $parts;
if (empty($this->parts['from'])) {
return false;
}
......@@ -1205,8 +1205,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if ($needsSubQuery) {
$subquery = $this->getLimitSubquery();
// what about composite keys?
$idColumnName = $table->getColumnName($table->getIdentifier());
switch (strtolower($this->_conn->getName())) {
case 'mysql':
// mysql doesn't support LIMIT in subqueries
......@@ -1215,11 +1215,11 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
break;
case 'pgsql':
// pgsql needs special nested LIMIT subquery
$subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias';
$subquery = 'SELECT doctrine_subquery_alias.' . $idColumnName . ' FROM (' . $subquery . ') AS doctrine_subquery_alias';
break;
}
$field = $this->getTableAlias($rootAlias) . '.' . $table->getIdentifier();
$field = $this->getTableAlias($rootAlias) . '.' . $idColumnName;
// only append the subquery if it actually contains something
if ($subquery !== '') {
......@@ -1236,7 +1236,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$q .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(', ', $this->parts['orderby']) : '';
if ($modifyLimit) {
$q = $this->_conn->modifyLimitQuery($q, $this->parts['limit'], $this->parts['offset']);
}
......
......@@ -143,7 +143,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
*
* @return string the built sql query
*/
public function getQuery()
public function getQuery($params = array())
{
$select = array();
......
......@@ -149,8 +149,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
} else {
$class = get_class($this);
// get the table of this class
$this->_table = Doctrine_Manager::getInstance()
->getTable($class);
$this->_table = Doctrine_Manager::getInstance()->getTable($class);
$exists = false;
}
......@@ -247,7 +246,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
/**
* isValid
*
* @return boolean whether or not this record passes all column validations
* @return boolean whether or not this record is valid
*/
public function isValid()
{
......@@ -428,13 +427,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*
* @param array $data data array to be cleaned
* @return integer
* @todo Better description. What exactly does this "cleaning" involve?
*/
public function cleanData(&$data)
{
$tmp = $data;
$data = array();
//Doctrine::dump($this->getTable()->getFieldNames());
foreach ($this->getTable()->getFieldNames() as $fieldName) {
if ( ! isset($tmp[$fieldName])) {
$data[$fieldName] = self::$_null;
......@@ -458,7 +457,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
$this->_values = array_merge($this->_values, $this->cleanData($data));
$this->_data = array_merge($this->_data, $data);
//Doctrine::dump($this->_data);
$this->prepareIdentifiers(true);
}
......@@ -639,7 +637,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
if ($this->_state === Doctrine_Record::STATE_TCLEAN ||
$this->_state === Doctrine_Record::STATE_CLEAN) {
$this->_modified = array();
}
......
......@@ -956,8 +956,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$fieldName = $parts[0];
}
$name = strtolower($parts[0]);
if ($prepend) {
$this->_columnNames = array_merge(array($fieldName => $name), $this->_columnNames);
$this->_fieldNames = array_merge(array($name => $fieldName), $this->_fieldNames);
} else {
$this->_columnNames[$fieldName] = $name;
$this->_fieldNames[$name] = $fieldName;
}
if ($length == null) {
switch ($type) {
......
......@@ -96,8 +96,8 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase
public function testExportModelFromDirectory()
{
Doctrine::createTablesFromModels(dirname(__FILE__) . DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export');
Doctrine::createTablesFromModels(dirname(__FILE__) . DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export');
$this->assertEqual($this->adapter->pop(), 'COMMIT');
$this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
......
......@@ -97,7 +97,7 @@ class Doctrine_Hydrate_Mock extends Doctrine_Hydrate
{
$this->data = $data;
}
public function getQuery()
public function getQuery($params = array())
{
}
......
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