Skip to content

Commit

Permalink
Remove SQLSrv\LastInsertId
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Feb 27, 2021
1 parent cab102f commit 02e3157
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 57 deletions.
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

0 comments on commit 02e3157

Please sign in to comment.