Skip to content

UniDAC adapter: GetDatabaseError raises for providers without an error-code table, hiding the real database error #98

Description

@bero

TBoldUniDACConnection.GetDatabaseError (Source/Persistence/UniDAC/BoldUniDACInterfaces.pas) translates a UniDAC exception into Bold's EBoldDatabaseError. It has error-code tables for SQL Server, InterBase and PostgreSQL, and for every other provider it raises Exception.Create('Error codes not implemented for ' + ProviderName). Found while adding SQLite to the UniDAC test setup.

Symptom

On any provider outside those three (SQLite here), every database error reaching the adapter's except blocks is replaced by "Error codes not implemented for SQLite". The real error - in this case no such table: BOLD_TYPE - never surfaces, so the failure cannot be diagnosed.

Root cause

GetDatabaseError is called from inside except handlers (ExecSQL, Open, Reopen, Close). A translator that raises its own exception there discards the exception it was asked to translate. The FireDAC adapter shows the intended default: no provider table, every error becomes a generic EBoldDatabaseError carrying class, code and message.

Fix

  • GetDatabaseError: providers without a code table fall through with bdetError; the generic path already includes sErrorDetail (class, ErrorCode, message). The raise is gone.
  • No SQLite table was added: mapping SQLITE_CONSTRAINT (19) to bdetUpdate would produce the fixed text "Failed to update database" and lose the original message, which is exactly the defect in another form. Retry classification for SQLITE_BUSY/SQLITE_LOCKED can be a separate decision if the SQLite runs show a need.

Files changed

  • Source/Persistence/UniDAC/BoldUniDACInterfaces.pas
  • UnitTest/Code/Persistence/UniDAC/Test.PersistenceUniDAC.pas

Testing

  • RED: TestGetDatabaseErrorKeepsTheOriginalErrorForProvidersWithoutCodeMap (a TUniConnection with ProviderName = 'SQLite', never opened; EUniError wrapping EDAError(19, 'UNIQUE constraint failed ...')) failed with "Error codes not implemented for SQLite"
  • GREEN after the fix; the original text survives in the EBoldDatabaseError message
  • UniDAC fixtures 13/13 on SQL Server and SQLite (UniDAC 11.0.1, Delphi 13); full suite through the UniDAC build 2195/2195 on both
  • Vendored UniDAC 10.4 on Delphi 12: fixtures 13/13 on SQL Server

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions