2021-03-01 16:26:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Ulmus\Repository;
|
|
|
|
|
2022-04-13 03:31:48 +00:00
|
|
|
use Ulmus\{Repository, Query, Ulmus, Common};
|
2021-03-01 16:26:06 +00:00
|
|
|
|
|
|
|
class MssqlRepository extends Repository {
|
2022-01-28 16:37:35 +00:00
|
|
|
/*
|
2021-03-01 16:26:06 +00:00
|
|
|
protected function finalizeQuery() : void
|
2021-03-09 15:25:46 +00:00
|
|
|
{
|
2021-03-01 16:26:06 +00:00
|
|
|
if ( null !== $offset = $this->queryBuilder->getFragment(Query\Offset::class) ) {
|
|
|
|
if ( null === $limit = $this->queryBuilder->getFragment(Query\Limit::class) ) {
|
|
|
|
throw new \Exception("Your offset query fragment is missing a LIMIT value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
# an order by is mandatory for mssql offset/limit
|
|
|
|
if ( null === $order = $this->queryBuilder->getFragment(Query\OrderBy::class) ) {
|
|
|
|
$this->orderBy("(SELECT 0)");
|
2022-04-13 03:31:48 +00:00
|
|
|
}
|
2021-03-01 16:26:06 +00:00
|
|
|
|
|
|
|
$mssqlOffset = new \Ulmus\Query\MsSQL\Offset();
|
|
|
|
|
|
|
|
$mssqlOffset->set($offset->offset, $limit->limit);
|
|
|
|
|
|
|
|
$this->queryBuilder->removeFragment($offset);
|
|
|
|
$this->queryBuilder->removeFragment($limit);
|
|
|
|
|
|
|
|
$this->queryBuilder->push($mssqlOffset);
|
|
|
|
}
|
|
|
|
elseif ( null !== $limit = $this->queryBuilder->getFragment(Query\Limit::class) ) {
|
2021-03-09 15:25:46 +00:00
|
|
|
|
2021-03-01 16:26:06 +00:00
|
|
|
if ( null !== $select = $this->queryBuilder->getFragment(Query\Select::class) ) {
|
|
|
|
$select->top = $limit->limit;
|
|
|
|
}
|
|
|
|
elseif ( null !== $delete = $this->queryBuilder->getFragment(Query\Delete::class) ) {
|
|
|
|
$delete->top = $limit->limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->queryBuilder->removeFragment($limit);
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 16:37:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
protected function finalizeQuery() : void
|
|
|
|
{
|
|
|
|
if ( null !== $offset = $this->queryBuilder->getFragment(Query\MsSQL\Offset::class) ) {
|
|
|
|
# an order by is mandatory for mssql offset/limit
|
|
|
|
if ( null === $order = $this->queryBuilder->getFragment(Query\OrderBy::class) ) {
|
|
|
|
$this->orderBy("(SELECT 0)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty ($offset->offset ) ) {
|
|
|
|
if ( null !== $select = $this->queryBuilder->getFragment(Query\Select::class) ) {
|
|
|
|
$select->top = $offset->limit;
|
|
|
|
}
|
|
|
|
elseif ( null !== $delete = $this->queryBuilder->getFragment(Query\Delete::class) ) {
|
|
|
|
$delete->top = $offset->limit;
|
|
|
|
}
|
|
|
|
$this->queryBuilder->removeFragment($offset);
|
|
|
|
}
|
|
|
|
elseif ( empty($offset->limit) ) {
|
|
|
|
throw new \Exception("Your offset query fragment is missing a LIMIT value.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 16:26:06 +00:00
|
|
|
|
2022-04-13 03:31:48 +00:00
|
|
|
protected function serverRequestCountRepository() : Repository
|
|
|
|
{
|
|
|
|
return new static($this->entityClass, $this->alias, $this->adapter);
|
|
|
|
}
|
2021-03-01 16:26:06 +00:00
|
|
|
}
|