Commit 8144e267 authored by Marco Pivetta's avatar Marco Pivetta

Merge branch 'feature/#2494-sqlsrv-reuse-statement'

Close #2494
parents c446c311 817b5149
......@@ -197,8 +197,17 @@ class SQLSrvStatement implements IteratorAggregate, Statement
}
}
$this->stmt = sqlsrv_query($this->conn, $this->sql, $this->params);
if ( ! $this->stmt) {
$stmt = sqlsrv_prepare($this->conn, $this->sql, $this->params);
if (!$stmt) {
throw SQLSrvException::fromSqlSrvErrors();
}
$this->stmt = $stmt;
}
if (!sqlsrv_execute($this->stmt)) {
throw SQLSrvException::fromSqlSrvErrors();
}
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Driver\SQLSrv;
use Doctrine\DBAL\Driver\SQLSrv\Driver;
use Doctrine\DBAL\Driver\SQLSrv\SQLSrvException;
use Doctrine\Tests\DbalFunctionalTestCase;
class StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
{
if (!extension_loaded('sqlsrv')) {
self::markTestSkipped('sqlsrv is not installed.');
}
parent::setUp();
if (!$this->_conn->getDriver() instanceof Driver) {
self::markTestSkipped('sqlsrv only test');
}
}
public function testFailureToPrepareResultsInException()
{
// use the driver connection directly to avoid having exception wrapped
$stmt = $this->_conn->getWrappedConnection()->prepare(null);
// it's impossible to prepare the statement without bound variables for SQL Server,
// so the preparation happens before the first execution when variables are already in place
$this->expectException(SQLSrvException::class);
$stmt->execute();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment