Skip to content

Comments

feat: add UniqueConstraintViolationException#9979

Open
michalsn wants to merge 1 commit intocodeigniter4:4.8from
michalsn:feat/unique-exception
Open

feat: add UniqueConstraintViolationException#9979
michalsn wants to merge 1 commit intocodeigniter4:4.8from
michalsn:feat/unique-exception

Conversation

@michalsn
Copy link
Member

Description
This PR adds:

  • UniqueConstraintViolationException (extends DatabaseException), thrown on duplicate key violations across all database drivers
  • $db->getLastException(): ?DatabaseException - when DBDebug is false, exceptions are not thrown. This method provides a reliable way to inspect the type of failure, since raw error codes from $db->error()['code'] differ across drivers
  • DatabaseException::getDatabaseCode(): int|string - exposes the native driver error code on the exception itself, as getCode() is constrained to int by PHP Throwable interface and cannot carry string SQLSTATE codes

getLastException() is intentionally a transitional API. The long-term direction is to drop DBDebug = false entirely (v5 ?), leaving exceptions as the only error signalling mechanism - consistent with how every other major PHP framework handles database errors.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added enhancement PRs that improve existing functionalities database Issues or pull requests that affect the database layer 4.8 PRs that target the `4.8` branch. labels Feb 21, 2026
@michalsn michalsn changed the title feat: add UniqueConstraintViolationException and getLastException() feat: add UniqueConstraintViolationException Feb 21, 2026
@michalsn michalsn added the breaking change Pull requests that may break existing functionalities label Feb 22, 2026
@paulbalandan paulbalandan deleted the branch codeigniter4:4.8 February 22, 2026 10:37
@paulbalandan paulbalandan reopened this Feb 22, 2026
@github-actions github-actions bot added the stale Pull requests with conflicts label Feb 23, 2026
fix rector

add docs

fix sqlite3

fix SQLSRV

fix Postgre

update changelog

fix Postgre test

refactor postgre

update Postgre handling

fix test
@michalsn michalsn force-pushed the feat/unique-exception branch from e212250 to c4fa06c Compare February 24, 2026 11:24
@michalsn michalsn removed the stale Pull requests with conflicts label Feb 24, 2026
@codeigniter4 codeigniter4 deleted a comment from github-actions bot Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. breaking change Pull requests that may break existing functionalities database Issues or pull requests that affect the database layer enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants