public function criteriaToQuery($criteria) { if ($criteria == null) { $criteria = new Criteria(); } $db = Database::connection(); // assemble a query string. // if exactQuery is specified - no problem. just run it. responsibility is on // the user ;-) if ($criteria->getExplicitQuery() != null) { return $criteria->getExplicitQuery(); } // ok - otherwise now we should counstruct the query $q = "SELECT "; if ($criteria->isDistinct()) { $q .= " DISTINCT "; } // check if the query has an explicit list of fields to selec if ($criteria->getExplicitFields() != null) { $q .= $criteria->getExplicitFields(); } else { $q .= $this->fieldListString(); } if ($criteria->getExplicitFrom() != null) { $q .= " FROM " . $criteria->getExplicitFrom(); } else { $q .= " FROM " . $this->tableName; } $whereString = $criteria->whereString(); if ($whereString != null) { $q .= " WHERE " . $criteria->whereString(); } $q .= " " . $criteria->groupByString(); $q .= " " . $criteria->orderString(); $q .= " " . $criteria->limitString(); if ($criteria->isForUpdate()) { $q .= " FOR UPDATE"; } return $q; }
public function criteriaToQueryForDelete($criteria) { if ($criteria == null) { $criteria = new Criteria(); } $db = Database::connection(); // assemble a query string. // if exactQuery is specified - no problem. just run it. responsibility is on // the user ;-) if ($criteria->getExplicitQuery() != null) { return $criteria->getExplicitQuery(); } // ok - otherwise now we should counstruct the query $q = "DELETE "; $q .= " FROM " . $this->tableName; $whereString = $criteria->whereString(); if ($whereString != null) { $q .= " WHERE " . $criteria->whereString(); } $q .= " " . $criteria->limitString(); return $q; }