8000 Use the same statement resource for repeated execution of the same statement on SQL Server by morozov · Pull Request #2494 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use the same statement resource for repeated execution of the same statement on SQL Server #2494

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

Merged
merged 1 commit into from
Sep 7, 2016
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
11 changes: 10 additions & 1 deletion lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,17 @@ public function execute($params = null)
}
}

$this->stmt = sqlsrv_query($this->conn, $this->sql, $this->params);
if ( ! $this->stmt) {
$stmt = sqlsrv_prepare($this->conn, $this->sql, $this->params);

if (!$stmt) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch should be tested.

Also, add empty lines around control structures

throw SQLSrvException::fromSqlSrvErrors();
}

$this->stmt = $stmt;
}

if (!sqlsrv_execute($this->stmt)) {
throw SQLSrvException::fromSqlSrvErrors();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Doctrine\Tests\DBAL\Functional\Driver\SQLSrv;

use Doctrine\DBAL\Driver\SQLSrv\Driver;
use Doctrine\Tests\DbalFunctionalTestCase;

class StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
{
if (!extension_loaded('sqlsrv')) {
$this->markTestSkipped('sqlsrv is not installed.');
}

parent::setUp();

if (!$this->_conn->getDriver() instanceof Driver) {
$this->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->setExpectedException('Doctrine\\DBAL\\Driver\\SQLSrv\\SQLSrvException');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use SQLSrvException::class here, since I think that we bumped version requirements to minimum PHP 5.5

$stmt->execute();
}
}
0