Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw an error if moveNext has no Records #20

Merged
merged 4 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
ports:
- "1433:1433"
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P Pa55word -Q 'SELECT 1'"
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -U sa -P Pa55word -Q 'SELECT 1'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
ports:
- "1433:1433"
healthcheck:
test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost,1433", "-U", "sa", "-P", "Pa55word", "-Q", "SELECT 1"]
test: ["CMD", "/opt/mssql-tools18/bin/sqlcmd", "-C", "-S", "localhost,1433", "-U", "sa", "-P", "Pa55word", "-Q", "SELECT 1"]
timeout: 20s
interval: 10s
retries: 10
Expand Down
12 changes: 5 additions & 7 deletions src/DbIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ByJG\AnyDataset\Db;

use ByJG\AnyDataset\Core\Exception\IteratorException;
use ByJG\AnyDataset\Core\GenericIterator;
use ByJG\AnyDataset\Core\Row;
use ByJG\Serializer\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -74,18 +73,17 @@ public function hasNext()

/**
* @return Row
* @throws IteratorException
* @throws InvalidArgumentException
*/
public function moveNext()
{
if (!$this->hasNext()) {
throw new IteratorException("No more records. Did you used hasNext() before moveNext()?");
} else {
$singleRow = array_shift($this->rowBuffer);
$this->currentRow++;
return $singleRow;
return null;
}

$singleRow = array_shift($this->rowBuffer);
$this->currentRow++;
return $singleRow;
}

public function key()
Expand Down
12 changes: 5 additions & 7 deletions src/Oci8Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ByJG\AnyDataset\Db;

use ByJG\AnyDataset\Core\Exception\IteratorException;
use ByJG\AnyDataset\Core\GenericIterator;
use ByJG\AnyDataset\Core\Row;
use ByJG\Serializer\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -86,18 +85,17 @@ public function __destruct()

/**
* @return mixed
* @throws IteratorException
* @throws InvalidArgumentException
*/
public function moveNext()
{
if (!$this->hasNext()) {
throw new IteratorException("No more records. Did you used hasNext() before moveNext()?");
} else {
$row = array_shift($this->rowBuffer);
$this->moveNextRow++;
return $row;
return null;
}

$row = array_shift($this->rowBuffer);
$this->moveNextRow++;
return $row;
}

public function key()
Expand Down