Permalink
Browse files

Final cleanups and optimizations in ModelCriterion logic

Refs #41
  • Loading branch information...
1 parent 827e8d2 commit ab1ffa34d35e6db3839f2d6d489b03387aa60562 @fzaninotto fzaninotto committed Jul 28, 2012
@@ -30,7 +30,7 @@
const UND = " AND ";
const ODER = " OR ";
- /** Value of the CO. */
+ /** Value of the criterion */
protected $value;
/**
@@ -39,31 +39,43 @@
*/
protected $comparison;
- /** Table name. */
+ /**
+ * Table name
+ * @var string
+ */
protected $table;
- /** Real table name */
+ /**
+ * Real table name
+ * @var string
+ */
protected $realtable;
- /** Column name. */
+ /**
+ * Column name
+ * @var string
+ */
protected $column;
/**
- * The DBAdaptor which might be used to get db specific
+ * The DBAdapter which might be used to get db specific
* variations of sql.
*/
protected $db;
/**
- * other connected criteria and their conjunctions.
+ * Other connected criterons
+ * @var [AbstractCriterion]
*/
protected $clauses = array();
+ /**
+ * Operators for connected criterions
+ * Only self::UND and self::ODER are accepted
+ * @var [String]
+ */
protected $conjunctions = array();
- /** "Parent" Criteria class */
- protected $parent;
-
/**
* Create a new instance.
*
@@ -252,10 +264,12 @@ public function addOr(AbstractCriterion $criterion)
*/
public function appendPsTo(&$sb, array &$params)
{
+ if (!$this->clauses) {
+ return $this->appendPsForUniqueClauseTo($sb, $params);
+ }
+ // if there are sub criterions, they must be combined to this criterion
$sb .= str_repeat ( '(', count($this->clauses) );
-
$this->appendPsForUniqueClauseTo($sb, $params);
-
foreach ($this->clauses as $key => $clause) {
$sb .= $this->conjunctions[$key];
$clause->appendPsTo($sb, $params);
@@ -24,9 +24,9 @@
/**
* Create a new instance.
*
- * @param Criteria $outer The outer class (this is an "inner" class).
- * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
- * @param ColumnMap $column A Column object to help escaping the value
+ * @param Criteria $outer The outer class (this is an "inner" class).
+ * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
+ * @param ColumnMap $column A Column object to help escaping the value
* @param mixed $value
* @param string $tableAlias optional table alias
*/
@@ -30,12 +30,12 @@ class RawModelCriterion extends AbstractModelCriterion
/**
* Create a new instance.
*
- * @param Criteria $outer The outer class (this is an "inner" class).
- * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
- * @param ColumnMap $column A Column object to help escaping the value
+ * @param Criteria $outer The outer class (this is an "inner" class).
+ * @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
+ * @param ColumnMap $column A Column object to help escaping the value
* @param mixed $value
* @param string $tableAlias optional table alias
- * @param string $type A PDO type constant, e.g. PDO::PARAM_STR
+ * @param string $type A PDO type constant, e.g. PDO::PARAM_STR
*/
public function __construct(Criteria $outer, $clause, $column, $value = null, $tableAlias = null, $type = PDO::PARAM_STR)
{
@@ -28,7 +28,6 @@
use Propel\Runtime\Query\Criteria;
use Propel\Runtime\Query\Criterion\AbstractCriterion;
use Propel\Runtime\Query\Criterion\InModelCriterion;
-use Propel\Runtime\Query\Criterion\BaseModelCriterion;
use Propel\Runtime\Query\Criterion\BasicModelCriterion;
use Propel\Runtime\Query\Criterion\CustomCriterion;
use Propel\Runtime\Query\Criterion\LikeModelCriterion;
@@ -92,7 +91,7 @@ class ModelCriteria extends Criteria implements \IteratorAggregate
// temporary property used in replaceNames
protected $currentAlias;
-
+
/**
* Creates a new instance with the default capacity which corresponds to
* the specified database.
@@ -1867,15 +1866,18 @@ protected function getCriterionForClause($clause, $value, $bindingType = null)
if (substr_count($clause, '?') > 1) {
return new SeveralModelCriterion($this, $clause, $colMap, $value, $this->currentAlias);
}
+
return new BasicModelCriterion($this, $clause, $colMap, $value, $this->currentAlias);
} else {
@hhamon
hhamon Jul 30, 2012 Member

No need for the else statement.

@fzaninotto
fzaninotto Jul 30, 2012 Member

Good catch! Created #284 for that.

// no column match in clause, must be an expression like '1=1'
if (false !== strpos($clause, '?')) {
if (null === $bindingType) {
throw new PropelException(sprintf('Cannot determine the column to bind to the parameter in clause "%s".', $clause));
}
+
return new RawCriterion($this, $clause, $value, $bindingType);
}
+
return new CustomCriterion($this, null, $clause);
}
}

0 comments on commit ab1ffa3

Please sign in to comment.