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

PDO::ATTR_ERRMODE is implicitly changed to PDO::ERRMODE_SILENT after PDO::lastInsertId() call fails #1331

Closed
mpyw opened this issue Nov 17, 2021 · 1 comment · Fixed by #1330

Comments

@mpyw
Copy link
Contributor

mpyw commented Nov 17, 2021

PHP version

PHP 8.1.0RC6

Note that GitHub Actions PHP image looks to use...

  • pdo_sqlsrv on PHP 8.1 and later
  • pdo_dblib on PHP 8.0 and before

Driver and SQL Server versions

PDO dump Information provided Laravel's dump() function:

PDO {#335
  inTransaction: false
  attributes: {
    CASE: NATURAL
    ERRMODE: SILENT
    PERSISTENT: false
    DRIVER_NAME: "sqlsrv"
    SERVER_INFO: array:3 [
      "CurrentDatabase" => "testing"
      "SQLServerVersion" => "15.00.4178"
      "SQLServerName" => "e6cf78d63667"
    ]
    ORACLE_NULLS: NATURAL
    CLIENT_VERSION: array:4 [
      "DriverName" => "libmsodbcsql-17.8.so.1.1"
      "DriverODBCVer" => "03.52"
      "DriverVer" => "17.08.0001"
      "ExtensionVer" => "5.10.0-beta1"
    ]
    SERVER_VERSION: "15.00.4178"
    STATEMENT_CLASS: array:1 [
      0 => "PDOStatement"
    ]
    EMULATE_PREPARES: false
    STRINGIFY_FETCHES: false
    DEFAULT_FETCH_MODE: BOTH
  }
}

Problem description

Described here: [PoC] PDO::ATTR_ERRMODE is implicitly changed to PDO::ERRMODE_SILENT after PDO::lastInsertId() call fails by mpyw · Pull Request #1 · mpyw/laravel-retry-on-duplicate-key

Overview

SQL Server handles auto-incrementing values differently than other RDBMS. I accidentally forgot to change the value of the $incrementing property of Model that is not auto-incremented. In this case, PDO::lastInsertId() is unexpectedly called and its call will fail. This is the intended design.

However, I found that after PDO::lastInsertId() failed, PDO::ATTR_ERRMODE was implicitly changed to PDO::ERRMODE_EXCEPTION and never restored. I'm convinced that this is a bug, so I submit a pull request to the pdo_sqlsrv repository.

Expected behavior and actual behavior

After PDO::lastInsertId() fails,

Expected

PDO::ERRMODE_SILENT is replaced by PDO::ERRMODE_EXCEPTION to restore original value.

Actual

PDO::ERRMODE_SILENT is never replaced.

Repro code or steps to reproduce

https://github.com/mpyw/laravel-retry-on-duplicate-key/blob/8fe6bc3ec72c37886e85b9e0817d6cedbe089db3/tests/Test.php

@yitam
Copy link
Contributor

yitam commented Nov 17, 2021

Thanks and please check my reply to PR #1330

@mpyw mpyw closed this as completed Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants