Skip to content

Commit

Permalink
Throw exception in OCI8Connection::lastInsertId() when no sequence na…
Browse files Browse the repository at this point in the history
…me is given
  • Loading branch information
BenMorel committed Nov 15, 2018
1 parent 2419e28 commit 1a0ff77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function exec(string $statement) : int
public function lastInsertId(string $name = null) : string
{
if ($name === null) {
return false;
throw new OCI8Exception('A sequence name must be provided.');
}

$sql = 'SELECT ' . $name . '.CURRVAL FROM DUAL';
Expand Down
6 changes: 5 additions & 1 deletion tests/Doctrine/Tests/DBAL/Functional/WriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional;

use DateTime;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Sequence;
Expand Down Expand Up @@ -189,7 +190,10 @@ public function testLastInsertIdNoSequenceGiven()
$this->markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns.");
}

self::assertSame('', $this->connection->lastInsertId(null));
$this->expectException(OCI8Exception::class);
$this->expectExceptionMessage('A sequence name must be provided.');

$this->connection->lastInsertId(null);
}

/**
Expand Down

0 comments on commit 1a0ff77

Please sign in to comment.