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

Remove SQLSrv\LastInsertId #4514

Merged
merged 1 commit into from
Feb 27, 2021
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
8 changes: 2 additions & 6 deletions src/Driver/SQLSrv/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ final class Connection implements ServerInfoAwareConnection
/** @var resource */
protected $conn;

/** @var LastInsertId */
protected $lastInsertId;

/**
* @internal The connection can be only instantiated by its driver.
*
Expand All @@ -50,8 +47,7 @@ public function __construct($serverName, $connectionOptions)
throw Error::new();
}

$this->conn = $conn;
$this->lastInsertId = new LastInsertId();
$this->conn = $conn;
}

/**
Expand All @@ -66,7 +62,7 @@ public function getServerVersion()

public function prepare(string $sql): DriverStatement
{
return new Statement($this->conn, $sql, $this->lastInsertId);
return new Statement($this->conn, $sql);
}

public function query(string $sql): ResultInterface
Expand Down
32 changes: 0 additions & 32 deletions src/Driver/SQLSrv/LastInsertId.php

This file was deleted.

21 changes: 2 additions & 19 deletions src/Driver/SQLSrv/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
use function assert;
use function is_int;
use function sqlsrv_execute;
use function sqlsrv_fetch;
use function sqlsrv_get_field;
use function sqlsrv_next_result;
use function SQLSRV_PHPTYPE_STREAM;
use function SQLSRV_PHPTYPE_STRING;
use function sqlsrv_prepare;
Expand Down Expand Up @@ -61,13 +58,6 @@ final class Statement implements StatementInterface
*/
private $types = [];

/**
* The last insert ID.
*
* @var LastInsertId|null
*/
private $lastInsertId;

/**
* Append to any INSERT query to retrieve the last insert id.
*/
Expand All @@ -79,7 +69,7 @@ final class Statement implements StatementInterface
* @param resource $conn
* @param string $sql
*/
public function __construct($conn, $sql, ?LastInsertId $lastInsertId = null)
public function __construct($conn, $sql)
{
$this->conn = $conn;
$this->sql = $sql;
Expand All @@ -88,8 +78,7 @@ public function __construct($conn, $sql, ?LastInsertId $lastInsertId = null)
return;
}

$this->sql .= self::LAST_INSERT_ID_SQL;
$this->lastInsertId = $lastInsertId;
$this->sql .= self::LAST_INSERT_ID_SQL;
}

/**
Expand Down Expand Up @@ -144,12 +133,6 @@ public function execute($params = null): ResultInterface
throw Error::new();
}

if ($this->lastInsertId !== null) {
sqlsrv_next_result($this->stmt);
sqlsrv_fetch($this->stmt);
$this->lastInsertId->setId(sqlsrv_get_field($this->stmt, 0));
}

return new Result($this->stmt);
}

Expand Down