Skip to content

Conversation

@amotl
Copy link
Member

@amotl amotl commented May 4, 2023

About

Running the standalone example programs added with GH-145 revealed lots of deprecation warnings and subsequent type errors.

Details

  1. Maintenance: Towards PHP8, by adding more type hints.
  2. Maintenance: Align PDO::errorCode() with official PDO specification 1.
    According to the specification, the function should return either an error code as string type, or null. Its signature is:
    public PDO::errorCode(): ?string
    
    On the other hand, our implementation returned int error codes. This changed now, and has been advertised properly as breaking change. Personally, I don't think it will have too much impact, as most error handling in userspace programs will be handled by exceptions anyway, as far as I could see, and within CrateConst.php, it looks like only ERR_INVALID_SQL had internal references at all. Please advise if you think this flaw should not be fixed, or differently.

Footnotes

  1. https://www.php.net/manual/en/pdo.errorcode.php

@amotl amotl force-pushed the amo/typing-more branch from 8b78f71 to 45e3500 Compare May 4, 2023 22:33
@amotl amotl requested review from matriv and seut May 5, 2023 10:17
@amotl amotl force-pushed the amo/typing-more branch 3 times, most recently from 2e09d8c to 25b190e Compare May 5, 2023 10:35
Copy link
Member

@seut seut left a comment

Choose a reason for hiding this comment

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

👍

According to the specification, the function should return either an error code as string type, or null

error code as string, unbelievable 🙄


- Maintenance: Added more type hints, mitigating lots of deprecation warnings.

Breaking changes
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Breaking changes
Breaking Changes

Copy link

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@amotl
Copy link
Member Author

amotl commented May 5, 2023

Error code as string?

PDO::errorCode()'s offical documentation states that it

returns an SQLSTATE, a five characters alphanumeric identifier defined in the ANSI SQL-92 standard.

So, I think PHP is correct on this detail. Whether we made a mistake in the past, by defining the error codes within CrateConst.php not quite correctly, and just forwarding CrateDB's error code 1:1, which originally appears to be in integer format 1, is beyond what I am currently able to grasp, i.e. I've not investigated it yet, and will be happy to hear back from you about it.

If you think we are up to something here, and the error code handling would need further adjustments, for example by mapping internal CrateDB error codes defined in CrateConst.php to the ones defined by ANSI SQL-92's SQLSTATE, and whether you think we need to go further here, please let me know. Now, it's the right time to fix such eventual shortcomings of previous versions.

Footnotes

  1. You can inspect at 2, that the code will be casting this to a string now, using $this->errorCode = strval($result['code']).

  2. https://github.com/crate/crate-pdo/pull/146/files#diff-d212dd2b5bd10a50c66f0b18298062aaebd573a232d2031daeded268e45d1e76

@amotl amotl force-pushed the amo/examples branch 2 times, most recently from e80a048 to a91aa3b Compare May 5, 2023 15:26
amotl added a commit to crate/crate-dbal that referenced this pull request May 5, 2023
SHOULD BE REMOVED AFTER INTEGRATING GH-146 [1].

[1] crate/crate-pdo#146
@seut
Copy link
Member

seut commented May 8, 2023

If you think we are up to something here, and the error code handling would need further adjustments, for example by mapping internal CrateDB error codes defined in CrateConst.php to the ones defined by ANSI SQL-92's SQLSTATE, and whether you think we need to go further here, please let me know. Now, it's the right time to fix such eventual shortcomings of previous versions.

CrateDB's error codes are currently somehow aligned with HTTP error codes instead of codes defined by the SQLSTATE. I think CrateDB itself should move on to SQLSTATE eventually for SQL Standard compatibility.
I'm not sure if the situation really improves if we map CrateDB's own codes to the SQLSTATE at one client only, I'd tend to leave out the mapping for now.

Base automatically changed from amo/examples to main May 8, 2023 20:15
@amotl amotl force-pushed the amo/typing-more branch 5 times, most recently from 2343fde to f03ae60 Compare May 8, 2023 22:24
@amotl amotl marked this pull request as ready for review May 8, 2023 22:26
amotl added 3 commits May 9, 2023 00:43
As per [1], `PDO::errorCode()` returns an error code as string type, or
`null`. The signature is:

  public PDO::errorCode(): ?string

[1] https://www.php.net/manual/en/pdo.errorcode.php
@amotl amotl force-pushed the amo/typing-more branch from f03ae60 to 748158d Compare May 8, 2023 22:48
@amotl amotl force-pushed the amo/typing-more branch from 748158d to d9a829b Compare May 8, 2023 22:55
Codecov complained a bit, with corresponding admonitions on GitHub's PR.
@amotl
Copy link
Member Author

amotl commented May 9, 2023

It took a few more adjustments to satisfy PHP's type checker wrt. PHP7 vs. PHP8 balancing, Codecov's patch coverage rules, and Scrutinizer's quality assessment. It looks like every validation step succeeded now.

-- https://scrutinizer-ci.com/g/crate/crate-pdo/inspections/dfe6c8e8-a803-438d-9027-516419fb7ac0

@amotl amotl merged commit 68af6e9 into main May 9, 2023
@amotl amotl deleted the amo/typing-more branch May 9, 2023 13:28
amotl added a commit to crate/crate-dbal that referenced this pull request Feb 12, 2025
SHOULD BE REMOVED AFTER INTEGRATING GH-146 [1].

[1] crate/crate-pdo#146
amotl added a commit to crate/crate-dbal that referenced this pull request Feb 12, 2025
SHOULD BE REMOVED AFTER INTEGRATING GH-146 [1].

[1] crate/crate-pdo#146
amotl added a commit to crate/crate-dbal that referenced this pull request Nov 13, 2025
SHOULD BE REMOVED AFTER INTEGRATING GH-146 [1].

[1] crate/crate-pdo#146
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 this pull request may close these issues.

4 participants