Инструменты пользователя

Инструменты сайта


limb3:en:architecture:criteria

Criteria

Criteria is a group of classes that allows you to build complex conditions for SQL queries using nice OO interface. The initial conception was adopted from Propel and later was a bit simplified.

UML Static Structure

}

Criteria classes

All criteria classes are children of lmbSQLBaseCriteria class that implements basic functionality to allow a composition of criteria.

Class nameDescription
lmbSQLRawCriteriaAllows to insert a condition into SQL query as is.
lmbSQLFieldCriteriaAllows to insert a condition on some field.
lmbSQLTableFieldCriteriaA child class of lmbSQLFieldCriteria. Requeres explicit table name.
SQLFielBetweenCriteriaAllows to insert between conditions into SQL query.
lmbSQLFalseCriteriaCritetia that is never passed.
lmbSQLTrueCriteriaCriteria that is always passed.

Criteria usage

Criteria are commonly used with lmbSelectQuery class to insert conditions into %where% and %having% placeholders.

Here is how lmbSQLFieldCriteria is used:

$query->addCondition(newSQLFieldCriteria('name', '%'.$name.'%', lmbSQLFieldCriteria :: LIKE));

It's possible to combine criteria objects:

    $criteria = new lmbSQLTableFieldCriteria('ingredient.name', '%'.$name.'%', lmbSQLFieldCriteria :: LIKE);
    $new_criteria = new lmbSQLTableFieldCriteria('ingredient.name', '%'.$name.'%', lmbSQLFieldCriteria :: LIKE);
    $criteria->addOr($new_criteria);
    $criteria->addAnd(new SQLFielBetweenCriteria('value', 10, 20));
    $query->addCondition($criteria);

Обсуждение

Ваш комментарий. Вики-синтаксис разрешён:
     __  __  __     __  _      __   ___ 
 __ / / / / / / __ / / | | /| / /  / _ |
/ // / / /_/ / / // /  | |/ |/ /  / __ |
\___/  \____/  \___/   |__/|__/  /_/ |_|
 
limb3/en/architecture/criteria.txt · Последние изменения: 2010/11/10 10:02 (внешнее изменение)