/** * build sql WHERE statement * * @param Db2PhpEntity $entity * @param bool $fullyQualifiedNames * @param bool $prependWhere * @return string */ public function buildSqlWhere(Db2PhpEntity $entity, $fullyQualifiedNames = true, $prependWhere = false) { if (!array_key_exists($this->field, $entity->getFieldNames())) { return null; } $sql = null; if ($prependWhere) { $sql .= ' WHERE '; } return $sql . $entity->getFieldNameByFieldId($this->getField(), $fullyQualifiedNames) . $this->getSqlOperator() . $this->getSqlParameterIdentifier($entity); }
/** * get sql ORDER BY part from DSCs * * @param Db2PhpEntity $entity entity instance * @param array $sort array of DSC instances * @return string */ public static function buildSqlOrderBy(Db2PhpEntity $entity, $sort) { if (null === $sort) { return ''; } if ($sort instanceof DSC) { $sort = array($sort); } $sql = null; $first = true; foreach ($sort as $s) { /* @var $s DSC */ if (!array_key_exists($s->getField(), $entity->getFieldNames())) { continue; } if ($first) { $sql .= ' ORDER BY '; $first = false; } else { $sql .= ','; } $sql .= $entity->getFieldNameByFieldId($s->getField()) . ' ' . $s->getModeSql(); } return $sql; }