Skip to content

fix(database): classify prepared query exceptions#10182

Open
memleakd wants to merge 5 commits intocodeigniter4:4.8from
memleakd:feat/prepared-query-exception-classification
Open

fix(database): classify prepared query exceptions#10182
memleakd wants to merge 5 commits intocodeigniter4:4.8from
memleakd:feat/prepared-query-exception-classification

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

@memleakd memleakd commented May 10, 2026

Description

This is a follow-up to #10162, based on @michalsn’s request to make prepared queries use the same typed database exceptions as normal queries.

Prepared query failures now go through the shared database exception classification, so they can throw or store UniqueConstraintViolationException and RetryableTransactionException when applicable. This also keeps getLastException() useful when DBDebug is disabled.

For Postgre, prepared execution now preserves SQLSTATE from the result diagnostics, matching the normal query path and avoiding classification from connection-level error text.

Note

This exposes the connection exception factory and last-exception setter to the database component as @internal methods so classification can stay centralized.

Tests cover the shared prepared-query failure path, DBDebug=false, and live unique-constraint behavior.

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

- Reuse semantic database exception classification for prepared query failures
- Store typed exceptions for prepared queries when DBDebug is disabled
- Document prepared query exception behavior

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label May 10, 2026
memleakd added 4 commits May 10, 2026 15:15
- Execute prepared statements through the send/get-result flow
- Classify Postgre prepared failures from structured SQLSTATE diagnostics

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
- Classify OCI8 unique and retryable transaction errors from string codes
- Add coverage for OCI8 string-code exception classification

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
- Capture native OCI8 statement errors during prepared execution
- Route OCI8 prepared failures through shared exception classification

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant