class Criteria implements IteratorAggregate
This is a utility class for holding criteria information for a query.
BasePeer constructs SQL statements based on the values in this class.
Constants
EQUAL |
Comparison type.
|
NOT_EQUAL |
Comparison type.
|
ALT_NOT_EQUAL |
Comparison type.
|
GREATER_THAN |
Comparison type.
|
LESS_THAN |
Comparison type.
|
GREATER_EQUAL |
Comparison type.
|
LESS_EQUAL |
Comparison type.
|
LIKE |
Comparison type.
|
NOT_LIKE |
Comparison type.
|
CONTAINS_ALL |
Comparison for array column types
|
CONTAINS_SOME |
Comparison for array column types
|
CONTAINS_NONE |
Comparison for array column types
|
ILIKE |
PostgreSQL comparison type
|
NOT_ILIKE |
PostgreSQL comparison type
|
CUSTOM |
Comparison type.
|
RAW |
Comparison type
|
CUSTOM_EQUAL |
Comparison type for update
|
DISTINCT |
Comparison type.
|
IN |
Comparison type.
|
NOT_IN |
Comparison type.
|
ALL |
Comparison type.
|
JOIN |
Comparison type.
|
BINARY_AND |
Binary math operator: AND
|
BINARY_OR |
Binary math operator: OR
|
ASC |
"Order by" qualifier - ascending
|
DESC |
"Order by" qualifier - descending
|
ISNULL |
"IS NULL" null comparison
|
ISNOTNULL |
"IS NOT NULL" null comparison
|
CURRENT_DATE |
"CURRENT_DATE" ANSI SQL function
|
CURRENT_TIME |
"CURRENT_TIME" ANSI SQL function
|
CURRENT_TIMESTAMP |
"CURRENT_TIMESTAMP" ANSI SQL function
|
LEFT_JOIN |
"LEFT JOIN" SQL statement
|
RIGHT_JOIN |
"RIGHT JOIN" SQL statement
|
INNER_JOIN |
"INNER JOIN" SQL statement
|
LOGICAL_OR |
logical OR operator
|
LOGICAL_AND |
logical AND operator
|
Methods
__construct(string $dbName = null)
Creates a new instance with the default capacity which corresponds to the specified database. |
||
getIterator()
Implementing SPL IteratorAggregate interface. |
||
Criterion[] |
getMap()
Get the criteria map, i.e. |
|
void |
clear()
Brings this criteria back to its initial state, so that it can be reused as if it was new. |
|
Criteria |
addAsColumn(string $name, string $clause)
Add an AS clause to the select columns. |
|
array |
getAsColumns()
Get the column aliases. |
|
string|null |
getColumnForAs(string $as)
Returns the column name associated with an alias (AS-column). |
|
Criteria |
addAlias(string $alias, string $table)
Allows one to specify an alias for a table that can be used in various parts of the SQL. |
|
Criteria |
removeAlias(string $alias)
Remove an alias for a table (useful when merging Criterias). |
|
array |
getAliases()
Returns the aliases for this Criteria |
|
string|null |
getTableForAlias(string $alias)
Returns the table name associated with an alias. |
|
array($tableName, |
getTableNameAndAlias(string $tableAliasOrName)
Returns the table name and alias based on a table alias or name. |
|
array |
keys()
Get the keys of the criteria map, i.e. |
|
boolean |
containsKey(string $column)
Does this Criteria object contain the specified key? |
|
boolean |
keyContainsValue(string $column)
Does this Criteria object contain the specified key and does it have a value set for the key |
|
boolean |
hasWhereClause()
Whether this Criteria has any where columns. |
|
void |
setUseTransaction(bool $v)
Will force the sql represented by this criteria to be executed within a transaction. |
|
boolean |
isUseTransaction()
Whether the sql command specified by this criteria must be wrapped in a transaction. |
|
Criterion |
getCriterion(string $column)
Method to return criteria related to columns in a table. |
|
Criterion |
getLastCriterion()
Method to return the latest Criterion in a table. |
|
Criterion |
getNewCriterion(string $column, mixed $value = null, string $comparison = self::EQUAL)
Method to return criterion that is not added automatically to this Criteria. |
|
string |
getColumnName(string $name)
Method to return a String table name. |
|
array |
getTablesColumns()
Shortcut method to get an array of columns indexed by table. |
|
string |
getComparison(string $key)
Method to return a comparison String. |
|
string |
getDbName()
Get the Database(Map) name. |
|
void |
setDbName(string $dbName = null)
Set the DatabaseMap name. |
|
string |
getPrimaryTableName()
Get the primary table for this Criteria. |
|
setPrimaryTableName(string $tableName)
Sets the primary table for this Criteria. |
||
string |
getTableName(string $name)
Method to return a String table name. |
|
mixed |
getValue(string $name)
Method to return the value that was added to Criteria. |
|
mixed |
get(string $key)
An alias to getValue() -- exposing a Hashtable-like interface. |
|
Criteria |
put(string $key, mixed $value)
Overrides Hashtable put, so that this object is returned instead of the value previously in the Criteria object. |
|
putAll(mixed $t)
Copies all of the mappings from the specified Map to this Criteria These mappings will replace any mappings that this Criteria had for any of the keys currently in the specified Map. |
||
Criteria |
add(string $critOrColumn, mixed $value = null, string $comparison = null)
This method adds a new criterion to the list of criterias. |
|
Criteria |
addCond(string $name, string $p1, mixed $value = null, string $comparison = null)
This method creates a new criterion but keeps it for later use with combine() Until combine() is called, the condition is not added to the query |
|
Criteria |
combine(array $criterions = array(), string $operator = self::LOGICAL_AND, string $name = null)
Combine several named criterions with a logical operator |
|
Criteria |
addJoin(mixed $left, mixed $right, mixed $joinType = null)
This is the way that you should add a join of two tables. |
|
Criteria |
addMultipleJoin(array $conditions, string $joinType = null)
Add a join with multiple conditions |
|
Criteria |
addJoinObject(Join $join)
Add a join object to the Criteria |
|
array |
getJoins()
Get the array of Joins. |
|
Criteria |
addSelectQuery(Criteria $subQueryCriteria, string $alias = null)
Adds a Criteria as subQuery in the From Clause. |
|
boolean |
hasSelectQueries()
Checks whether this Criteria has a subquery. |
|
Criteria[] |
getSelectQueries()
Get the associative array of Criteria for the subQueries per alias. |
|
Criteria |
getSelectQuery(string $alias)
Get the Criteria for a specific subQuery. |
|
boolean |
hasSelectQuery(string $alias)
checks if the Criteria for a specific subQuery is set. |
|
forgeSelectQueryAlias()
|
||
Criteria |
setAll()
Adds "ALL" modifier to the SQL statement. |
|
Criteria |
setDistinct()
Adds "DISTINCT" modifier to the SQL statement. |
|
Criteria |
addSelectModifier(string $modifier)
Adds a modifier to the SQL statement. |
|
Criteria |
removeSelectModifier(string $modifier)
Removes a modifier to the SQL statement. |
|
bool |
hasSelectModifier(string $modifier)
Checks the existence of a SQL select modifier |
|
Criteria |
setIgnoreCase(boolean $b)
Sets ignore case. |
|
boolean |
isIgnoreCase()
Is ignore case on or off? |
|
Criteria |
setSingleRecord(boolean $b)
Set single record? Set this to |
|
boolean |
isSingleRecord()
Is single record? |
|
Criteria |
setLimit(int $limit)
Set limit. |
|
int |
getLimit()
Get limit. |
|
Criteria |
setOffset(int $offset)
Set offset. |
|
int |
getOffset()
Get offset. |
|
Criteria |
addSelectColumn(string $name)
Add select column. |
|
Criteria |
setComment(string $comment = null)
Set the query comment, that appears after the first verb in the SQL query |
|
string |
getComment()
Get the query comment, that appears after the first verb in the SQL query |
|
boolean |
hasSelectClause()
Whether this Criteria has any select columns. |
|
array |
getSelectColumns()
Get select columns. |
|
Criteria |
clearSelectColumns()
Clears current select columns. |
|
array |
getSelectModifiers()
Get select modifiers. |
|
Criteria |
addGroupByColumn(string $groupBy)
Add group by column name. |
|
Criteria |
addAscendingOrderByColumn(string $name)
Add order by column name, explicitly specifying ascending. |
|
Criteria |
addDescendingOrderByColumn(string $name)
Add order by column name, explicitly specifying descending. |
|
array |
getOrderByColumns()
Get order by columns. |
|
Criteria |
clearOrderByColumns()
Clear the order-by columns. |
|
Criteria |
clearGroupByColumns()
Clear the group-by columns. |
|
array |
getGroupByColumns()
Get group by columns. |
|
Criterion |
getHaving()
Get Having Criterion. |
|
mixed|null |
remove(string $key)
Remove an object from the criteria. |
|
string |
toString()
Build a string representation of the Criteria. |
|
int |
size()
Returns the size (count) of this criteria. |
|
boolean |
equals(Criteria|null $crit)
This method checks another Criteria to see if they contain the same attributes and hashtable entries. |
|
Criteria |
mergeWith(Criteria $criteria, string $operator = null)
Add the content of a Criteria to the current Criteria In case of conflict, the current Criteria keeps its properties |
|
Criteria |
addHaving(mixed $p1, mixed $value = null, mixed $comparison = null)
This method adds a prepared Criterion object to the Criteria as a having clause. |
|
Criteria |
addAnd(mixed $p1, mixed $value = null, mixed $comparison = null, bool $preferColumnCondition = true)
If a criterion for the requested column already exists, the condition is "AND"ed to the existing criterion (necessary for Propel 1.4 compatibility). |
|
Criteria |
addOr(mixed $p1, mixed $value = null, mixed $comparison = null, bool $preferColumnCondition = true)
If a criterion for the requested column already exists, the condition is "OR"ed to the existing criterion (necessary for Propel 1.4 compatibility). |
|
Criteria |
addUsingOperator(string|Criterion $p1, mixed $value = null, string $operator = null, boolean $preferColumnCondition = true)
Overrides Criteria::add() to use the default combine operator |
|
Criteria |
_or()
|
|
Criteria |
_and()
|
|
PropelConditionalProxy|Criteria |
_if(bool $cond)
Returns the current object if the condition is true, or a PropelConditionalProxy instance otherwise. |
|
PropelConditionalProxy|Criteria |
_elseif(bool $cond)
Returns a PropelConditionalProxy instance. |
|
PropelConditionalProxy|Criteria |
_else()
Returns a PropelConditionalProxy instance. |
|
Criteria |
_endif()
Returns the current object Allows for conditional statements in a fluid interface. |
|
__clone()
Ensures deep cloning of attached objects |
Details
at line 272
public
__construct(string $dbName = null)
Creates a new instance with the default capacity which corresponds to the specified database.
at line 282
public
getIterator()
Implementing SPL IteratorAggregate interface.
This allows you to foreach () over a Criteria object.
at line 292
public Criterion[]
getMap()
Get the criteria map, i.e.
the array of Criterions
at line 304
public void
clear()
Brings this criteria back to its initial state, so that it can be reused as if it was new.
Except if the criteria has grown in capacity, it is left at the current capacity.
at line 346
public Criteria
addAsColumn(string $name, string $clause)
Add an AS clause to the select columns.
Usage:
Criteria myCrit = new Criteria();
myCrit->addAsColumn("alias", "ALIAS(".MyPeer::ID.")");
at line 359
public array
getAsColumns()
Get the column aliases.
at line 371
public string|null
getColumnForAs(string $as)
Returns the column name associated with an alias (AS-column).
at line 389
public Criteria
addAlias(string $alias, string $table)
Allows one to specify an alias for a table that can be used in various parts of the SQL.
at line 403
public Criteria
removeAlias(string $alias)
Remove an alias for a table (useful when merging Criterias).
at line 415
public array
getAliases()
Returns the aliases for this Criteria
at line 427
public string|null
getTableForAlias(string $alias)
Returns the table name associated with an alias.
at line 445
public array($tableName,
getTableNameAndAlias(string $tableAliasOrName)
Returns the table name and alias based on a table alias or name.
Use this method to get the details of a table name that comes in a clause, which can be either a table name or an alias name.
at line 463
public array
keys()
Get the keys of the criteria map, i.e.
the list of columns bearing a condition
printr($c->keys());
=> array('book.price', 'book.title', 'author.firstname')
at line 475
public boolean
containsKey(string $column)
Does this Criteria object contain the specified key?
at line 489
public boolean
keyContainsValue(string $column)
Does this Criteria object contain the specified key and does it have a value set for the key
at line 504
public boolean
hasWhereClause()
Whether this Criteria has any where columns.
This counts conditions added with the add() method.
at line 519
public void
setUseTransaction(bool $v)
Will force the sql represented by this criteria to be executed within a transaction.
This is here primarily to support the oid type in postgresql. Though it can be used to require any single sql statement to use a transaction.
at line 530
public boolean
isUseTransaction()
Whether the sql command specified by this criteria must be wrapped in a transaction.
at line 545
public Criterion
getCriterion(string $column)
Method to return criteria related to columns in a table.
Make sure you call containsKey($column) prior to calling this method, since no check on the existence of the $column is made in this method.
at line 555
public Criterion
getLastCriterion()
Method to return the latest Criterion in a table.
at line 577
public Criterion
getNewCriterion(string $column, mixed $value = null, string $comparison = self::EQUAL)
Method to return criterion that is not added automatically to this Criteria.
This can be used to chain the Criterions to form a more complex where clause.
at line 589
public string
getColumnName(string $name)
Method to return a String table name.
at line 610
public array
getTablesColumns()
Shortcut method to get an array of columns indexed by table.
printr($c->getTablesColumns());
=> array(
'book' => array('book.price', 'book.title'),
'author' => array('author.firstname')
)
at line 628
public string
getComparison(string $key)
Method to return a comparison String.
at line 642
public string
getDbName()
Get the Database(Map) name.
at line 655
public void
setDbName(string $dbName = null)
Set the DatabaseMap name.
If null
is supplied, uses value
provided by Propel::getDefaultDB()
.
at line 669
public string
getPrimaryTableName()
Get the primary table for this Criteria.
This is useful for cases where a Criteria may not contain any SELECT columns or WHERE columns. This must be explicitly set, of course, in order to be useful.
at line 683
public
setPrimaryTableName(string $tableName)
Sets the primary table for this Criteria.
This is useful for cases where a Criteria may not contain any SELECT columns or WHERE columns. This must be explicitly set, of course, in order to be useful.
at line 695
public string
getTableName(string $name)
Method to return a String table name.
at line 711
public mixed
getValue(string $name)
Method to return the value that was added to Criteria.
at line 727
public mixed
get(string $key)
An alias to getValue() -- exposing a Hashtable-like interface.
at line 747
public Criteria
put(string $key, mixed $value)
Overrides Hashtable put, so that this object is returned instead of the value previously in the Criteria object.
The reason is so that it more closely matches the behavior of the add() methods. If you want to get the previous value then you should first Criteria.get() it yourself. Note, if you attempt to pass in an Object that is not a String, it will throw a NPE. The reason for this is that none of the add() methods support adding anything other than a String as a key.
at line 762
public
putAll(mixed $t)
Copies all of the mappings from the specified Map to this Criteria These mappings will replace any mappings that this Criteria had for any of the keys currently in the specified Map.
if the map was another Criteria, its attributes are copied to this Criteria, overwriting previous settings.
at line 798
public Criteria
add(string $critOrColumn, mixed $value = null, string $comparison = null)
This method adds a new criterion to the list of criterias.
If a criterion for the requested column already exists, it is replaced. If is used as follow:
$crit = new Criteria();
$crit->add($column, $value, Criteria::GREATER_THAN);
Any comparison can be used.
The name of the table must be used implicitly in the column name, so the Column name must be something like 'TABLE.id'.
at line 833
public Criteria
addCond(string $name, string $p1, mixed $value = null, string $comparison = null)
This method creates a new criterion but keeps it for later use with combine() Until combine() is called, the condition is not added to the query
$crit = new Criteria();
$crit->addCond('cond1', $column1, $value1, Criteria::GREATERTHAN);
$crit->addCond('cond2', $column2, $value2, Criteria::EQUAL);
$crit->combine(array('cond1', 'cond2'), Criteria::LOGICALOR);
Any comparison can be used.
The name of the table must be used implicitly in the column name, so the Column name must be something like 'TABLE.id'.
at line 851
public Criteria
combine(array $criterions = array(), string $operator = self::LOGICAL_AND, string $name = null)
Combine several named criterions with a logical operator
at line 892
public Criteria
addJoin(mixed $left, mixed $right, mixed $joinType = null)
This is the way that you should add a join of two tables.
Example usage:
$c->addJoin(ProjectPeer::ID, FooPeer::PROJECTID, Criteria::LEFTJOIN);
// LEFT JOIN FOO ON (PROJECT.ID = FOO.PROJECT_ID)
at line 950
public Criteria
addMultipleJoin(array $conditions, string $joinType = null)
Add a join with multiple conditions
at line 1008
public Criteria
addJoinObject(Join $join)
Add a join object to the Criteria
at line 1030
public array
getJoins()
Get the array of Joins.
at line 1043
public Criteria
addSelectQuery(Criteria $subQueryCriteria, string $alias = null)
Adds a Criteria as subQuery in the From Clause.
at line 1058
public boolean
hasSelectQueries()
Checks whether this Criteria has a subquery.
at line 1068
public Criteria[]
getSelectQueries()
Get the associative array of Criteria for the subQueries per alias.
at line 1080
public Criteria
getSelectQuery(string $alias)
Get the Criteria for a specific subQuery.
at line 1092
public boolean
hasSelectQuery(string $alias)
checks if the Criteria for a specific subQuery is set.
at line 1097
public
forgeSelectQueryAlias()
at line 1113
public Criteria
setAll()
Adds "ALL" modifier to the SQL statement.
at line 1126
public Criteria
setDistinct()
Adds "DISTINCT" modifier to the SQL statement.
at line 1142
public Criteria
addSelectModifier(string $modifier)
Adds a modifier to the SQL statement.
e.g. self::ALL, self::DISTINCT, 'SQLCALCFOUNDROWS', 'HIGHPRIORITY', etc.
at line 1160
public Criteria
removeSelectModifier(string $modifier)
Removes a modifier to the SQL statement.
Checks for existence before removal
at line 1174
public bool
hasSelectModifier(string $modifier)
Checks the existence of a SQL select modifier
at line 1186
public Criteria
setIgnoreCase(boolean $b)
Sets ignore case.
at line 1198
public boolean
isIgnoreCase()
Is ignore case on or off?
at line 1216
public Criteria
setSingleRecord(boolean $b)
Set single record? Set this to true
if you expect the query to result in only a single result record (the default behaviour is to throw a PropelException if multiple records are returned when the query is executed).
This should be used in situations where returning multiple rows would indicate an error of some sort. If your query might return multiple records but you are only interested in the first one then you should be using setLimit(1).
at line 1228
public boolean
isSingleRecord()
Is single record?
at line 1240
public Criteria
setLimit(int $limit)
Set limit.
at line 1253
public int
getLimit()
Get limit.
at line 1266
public Criteria
setOffset(int $offset)
Set offset.
at line 1278
public int
getOffset()
Get offset.
at line 1290
public Criteria
addSelectColumn(string $name)
Add select column.
at line 1304
public Criteria
setComment(string $comment = null)
Set the query comment, that appears after the first verb in the SQL query
at line 1316
public string
getComment()
Get the query comment, that appears after the first verb in the SQL query
at line 1330
public boolean
hasSelectClause()
Whether this Criteria has any select columns.
This will include columns added with addAsColumn() method.
at line 1340
public array
getSelectColumns()
Get select columns.
at line 1350
public Criteria
clearSelectColumns()
Clears current select columns.
at line 1362
public array
getSelectModifiers()
Get select modifiers.
at line 1374
public Criteria
addGroupByColumn(string $groupBy)
Add group by column name.
at line 1388
public Criteria
addAscendingOrderByColumn(string $name)
Add order by column name, explicitly specifying ascending.
at line 1402
public Criteria
addDescendingOrderByColumn(string $name)
Add order by column name, explicitly specifying descending.
at line 1414
public array
getOrderByColumns()
Get order by columns.
at line 1424
public Criteria
clearOrderByColumns()
Clear the order-by columns.
at line 1436
public Criteria
clearGroupByColumns()
Clear the group-by columns.
at line 1448
public array
getGroupByColumns()
Get group by columns.
at line 1458
public Criterion
getHaving()
Get Having Criterion.
at line 1470
public mixed|null
remove(string $key)
Remove an object from the criteria.
at line 1490
public string
toString()
Build a string representation of the Criteria.
at line 1518
public int
size()
Returns the size (count) of this criteria.
at line 1531
public boolean
equals(Criteria|null $crit)
This method checks another Criteria to see if they contain the same attributes and hashtable entries.
at line 1599
public Criteria
mergeWith(Criteria $criteria, string $operator = null)
Add the content of a Criteria to the current Criteria In case of conflict, the current Criteria keeps its properties
at line 1694
public Criteria
addHaving(mixed $p1, mixed $value = null, mixed $comparison = null)
This method adds a prepared Criterion object to the Criteria as a having clause.
You can get a new, empty Criterion object with the getNewCriterion() method.
$crit = new Criteria();
$c = $crit->getNewCriterion(BasePeer::ID, 5, Criteria::LESS_THAN);
$crit->addHaving($c);
at line 1757
public Criteria
addAnd(mixed $p1, mixed $value = null, mixed $comparison = null, bool $preferColumnCondition = true)
If a criterion for the requested column already exists, the condition is "AND"ed to the existing criterion (necessary for Propel 1.4 compatibility).
If no criterion for the requested column already exists, the condition is "AND"ed to the latest criterion. If no criterion exist, the condition is added a new criterion
Any comparison can be used.
Supports a number of different signatures: - addAnd(column, value, comparison) - addAnd(column, value) - addAnd(Criterion)
at line 1793
public Criteria
addOr(mixed $p1, mixed $value = null, mixed $comparison = null, bool $preferColumnCondition = true)
If a criterion for the requested column already exists, the condition is "OR"ed to the existing criterion (necessary for Propel 1.4 compatibility).
If no criterion for the requested column already exists, the condition is "OR"ed to the latest criterion. If no criterion exist, the condition is added a new criterion
Any comparison can be used.
Supports a number of different signatures: - addOr(column, value, comparison) - addOr(column, value) - addOr(Criterion)
at line 1832
public Criteria
addUsingOperator(string|Criterion $p1, mixed $value = null, string $operator = null, boolean $preferColumnCondition = true)
Overrides Criteria::add() to use the default combine operator
at line 1848
public Criteria
_or()
at line 1858
public Criteria
_and()
at line 1876
public PropelConditionalProxy|Criteria
_if(bool $cond)
Returns the current object if the condition is true, or a PropelConditionalProxy instance otherwise.
Allows for conditional statements in a fluid interface.
at line 1893
public PropelConditionalProxy|Criteria
_elseif(bool $cond)
Returns a PropelConditionalProxy instance.
Allows for conditional statements in a fluid interface.
at line 1910
public PropelConditionalProxy|Criteria
_else()
Returns a PropelConditionalProxy instance.
Allows for conditional statements in a fluid interface.
at line 1927
public Criteria
_endif()
Returns the current object Allows for conditional statements in a fluid interface.
at line 1946
public
__clone()
Ensures deep cloning of attached objects