diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-14 20:22:53 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-14 20:22:53 +0200 |
commit | 10d76fff64363ea59d916b550854cf3540dadfbc (patch) | |
tree | 97fffd75698701dbdd3f737ca5b9d88b908b22af | |
parent | b567d32b0e51fda52308cc3b64e8c21c969d33eb (diff) |
fix operator for paging
-rw-r--r-- | db/itemmapper.php | 13 | ||||
-rw-r--r-- | tests/unit/db/ItemMapperTest.php | 6 |
2 files changed, 13 insertions, 6 deletions
diff --git a/db/itemmapper.php b/db/itemmapper.php index ff17596c2..d3c8164ae 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -166,12 +166,19 @@ class ItemMapper extends Mapper implements IMapper { return $this->findEntities($sql, $params); } + private function getOperator($oldestFirst) { + if($oldestFirst) { + return '>'; + } else { + return '<'; + } + } public function findAllFeed($id, $limit, $offset, $status, $userId, $oldestFirst=false){ $params = [$userId, $id]; $sql = 'AND `items`.`feed_id` = ? '; if($offset !== 0){ - $sql .= 'AND `items`.`id` < ? '; + $sql .= 'AND `items`.`id` ' . $this->getOperator($oldestFirst) . ' ? '; $params[] = $offset; } $sql = $this->makeSelectQueryStatus($sql, $status, $oldestFirst); @@ -183,7 +190,7 @@ class ItemMapper extends Mapper implements IMapper { $params = [$userId, $id]; $sql = 'AND `feeds`.`folder_id` = ? '; if($offset !== 0){ - $sql .= 'AND `items`.`id` < ? '; + $sql .= 'AND `items`.`id` ' . $this->getOperator($oldestFirst) . ' ? '; $params[] = $offset; } $sql = $this->makeSelectQueryStatus($sql, $status, $oldestFirst); @@ -195,7 +202,7 @@ class ItemMapper extends Mapper implements IMapper { $params = [$userId]; $sql = ''; if($offset !== 0){ - $sql .= 'AND `items`.`id` < ? '; + $sql .= 'AND `items`.`id` ' . $this->getOperator($oldestFirst) . ' ? '; $params[] = $offset; } $sql = $this->makeSelectQueryStatus($sql, $status, $oldestFirst); diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index 7a855b7bb..629d7da38 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -234,7 +234,7 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { public function testFindAllFeedOldestFirst(){ $sql = 'AND `items`.`feed_id` = ? ' . - 'AND `items`.`id` < ? '; + 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->id, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); @@ -272,7 +272,7 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { public function testFindAllFolderOldestFirst(){ $sql = 'AND `feeds`.`folder_id` = ? ' . - 'AND `items`.`id` < ? '; + 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->id, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); @@ -308,7 +308,7 @@ class ItemMapperTest extends \OCP\AppFramework\Db\MapperTestUtility { public function testFindAllOldestFirst(){ - $sql = 'AND `items`.`id` < ? '; + $sql = 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->offset]; $this->setMapperResult($sql, $params, $this->rows); |