protected function makeResrictionForAsscotion(array &$arrDataRow, $sFromTableName = null, array $arrFromKeys, $sToTableName = null, array $arrToKeys) { $aRestriction = new Restriction(); foreach ($arrFromKeys as $nIdx => $sFromKey) { if ($sFromTableName) { $sFromKey = $sFromTableName . '.' . $sFromKey; } $aRestriction->expression(array(SQL::createRawColumn($sToTableName, $arrToKeys[$nIdx]), '=', SQL::transValue($arrDataRow[$sFromKey])), true, true); } return $aRestriction; }
/** * 把一个 Restriction 实例添加到条件集合中去. * @param self 被添加的Restriction对象 * @return self */ public function add(self $aOtherRestriction, $bLogicAnd = true) { $arrRawSql =& $aOtherRestriction->rawSql(); $sIndex = spl_object_hash($aOtherRestriction); $bEmpty = empty($this->arrRawSql['subtree']); $this->arrRawSql['subtree'][$sIndex] = array('expr_type' => 'expression', 'subtree' => &$arrRawSql['subtree']); if (!empty($arrRawSql['factors'])) { $this->arrRawSql['subtree'][$sIndex]['factors'] =& $arrRawSql['factors']; } if (!$bEmpty) { $this->arrRawSql['subtree'][$sIndex]['pretree'][] = $bLogicAnd ? 'AND' : 'OR'; } return $this; }
public static function buildRestriction(Prototype $aPrototype, $values = null, $keys = null) { if ($values === null) { return null; } $keys = $keys ? (array) $keys : $aPrototype->keys(); if ($values instanceof Restriction) { return $values; } else { $aRestriction = new Restriction(); $sSqlTableAlias = $aPrototype->sqlTableAlias(); $values = array_values((array) $values); foreach ($keys as $nIdx => $sKey) { list($sTable, $sColumn) = SQL::splitColumn($sKey); $aRestriction->expression(array(SQL::createRawColumn($sTable, $sColumn), '=', SQL::transValue($values[$nIdx])), true, true); } return $aRestriction; } }