public function doSimpleQuery(Where $where = null) { if ($where === null) { $where = new Where(); } $sql = strtr("select :fields from :relation where :condition", [':fields' => $this->createProjection()->formatFieldsWithFieldAlias(), ':relation' => $this->getStructure()->getRelation(), ':condition' => (string) $where]); return $this->query($sql, $where->getValues()); }
/** * fetchSingleValue * * Fetch a single value named « result » from a query. * The query must be formatted with ":condition" as WHERE condition * placeholder. If the $where argument is a string, it is turned into a * Where instance. * * @access protected * @param string $sql * @param mixed $where * @param array $values * @return mixed */ protected function fetchSingleValue($sql, $where, array $values) { if (!$where instanceof Where) { $where = new Where($where, $values); } $sql = str_replace(":condition", (string) $where, $sql); return $this->getSession()->getClientUsingPooler('query_manager', '\\PommProject\\Foundation\\PreparedQuery\\PreparedQueryManager')->query($sql, $where->getValues())->current()['result']; }
/** * deleteWhere * * Delete records by a given condition. A collection of all deleted entries is returned. * * @param $where * @param array $values * @return CollectionIterator */ public function deleteWhere($where, array $values = []) { if (!$where instanceof Where) { $where = new Where($where, $values); } $sql = strtr("delete from :relation where :condition returning :projection", [':relation' => $this->getStructure()->getRelation(), ':condition' => (string) $where, ':projection' => $this->createProjection()->formatFieldsWithFieldAlias()]); $collection = $this->query($sql, $where->getValues()); foreach ($collection as $entity) { $entity->status(FlexibleEntityInterface::STATUS_NONE); } $collection->rewind(); return $collection; }