Skip to content

Commit

Permalink
Ported tests from doctrine#2487 and doctrine#2489
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 27, 2016
1 parent ff6a12f commit 1e93047
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Driver\IBMDB2\DB2Driver as IbmDb2Driver;
use Doctrine\DBAL\Driver\OCI8\Driver as Oci8Driver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SqlSrvDriver;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;

Expand Down Expand Up @@ -79,4 +82,54 @@ public function testFetchLongBlob()
);
$this->assertSame($data, stream_get_contents($stream));
}

public function testIncompletelyFetchedStatementDoesNotBlockConnection()
{
$table = new Table('stmt_test_non_fetched');
$table->addColumn('id', 'integer');
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->insert('stmt_test_non_fetched', array('id' => 1));
$this->_conn->insert('stmt_test_non_fetched', array('id' => 2));

$stmt1 = $this->_conn->prepare('SELECT id FROM stmt_test_non_fetched');
$stmt1->execute();
$stmt1->fetch();
$stmt1->execute();
// fetching only one record out of two
$stmt1->fetch();

$stmt2 = $this->_conn->prepare('SELECT id FROM stmt_test_non_fetched WHERE id = ?');
$stmt2->execute(array(1));
$this->assertEquals(1, $stmt2->fetchColumn());
}

public function testReuseStatementAfterClosingCursor()
{
$driver = $this->_conn->getDriver();

if ($driver instanceof IbmDb2Driver
|| $driver instanceof Oci8Driver
|| $driver instanceof SqlSrvDriver
) {
$this->markTestSkipped('This test will currently fail on IBM DB2, Oracle and MS SQL Server');
}

$table = new Table('stmt_test_close_cursor');
$table->addColumn('id', 'integer');
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->insert('stmt_test_close_cursor', array('id' => 1));
$this->_conn->insert('stmt_test_close_cursor', array('id' => 2));

$stmt = $this->_conn->prepare('SELECT id FROM stmt_test_close_cursor WHERE id = ?');

$stmt->execute(array(1));
$id = $stmt->fetchColumn();
$this->assertEquals(1, $id);

$stmt->closeCursor();

$stmt->execute(array(2));
$id = $stmt->fetchColumn();
$this->assertEquals(2, $id);
}
}

0 comments on commit 1e93047

Please sign in to comment.