Lightweight 0.20260625.0
Loading...
Searching...
No Matches
Lightweight::SqlFaultSource Class Referenceabstract

Substitutes a scripted failure for an ODBC call that actually succeeded. More...

#include <Utils.hpp>

Public Member Functions

 SqlFaultSource (SqlFaultSource const &)=delete
 
SqlFaultSourceoperator= (SqlFaultSource const &)=delete
 
 SqlFaultSource (SqlFaultSource &&)=delete
 
SqlFaultSourceoperator= (SqlFaultSource &&)=delete
 
virtual std::optional< SqlErrorInfoNextFailure (SQLHSTMT hStmt, std::source_location const &sourceLocation)=0
 Decides whether the next statement-handle check should fail.
 

Detailed Description

Substitutes a scripted failure for an ODBC call that actually succeeded.

Exists so error-recovery paths can be driven from a test. Some failures cannot be provoked through a real driver at all: a backup worker's transient-error retry arm needs a class-08 or HYT00 SQLSTATE, but every fault reachable from a test file (unreachable driver, unwritable path, dropped table) surfaces as HY000, which the retry policy classifies as non-transient. Without a seam those arms are unreachable rather than merely untested.

Production code never installs one: with no source configured, RequireSuccess consults nothing and returns on success exactly as before. This mirrors SqlDiagnosticSource and SqlLogger::SetLogger, injection mechanisms the project already uses.

See also
SetFaultSource

Definition at line 477 of file Utils.hpp.

Member Function Documentation

◆ NextFailure()

virtual std::optional< SqlErrorInfo > Lightweight::SqlFaultSource::NextFailure ( SQLHSTMT  hStmt,
std::source_location const &  sourceLocation 
)
pure virtual

Decides whether the next statement-handle check should fail.

Called by RequireSuccess for a call that the driver reported as successful. Returning an engaged optional makes RequireSuccess throw SqlException carrying that diagnostic, as though the driver had failed.

Warning
RequireSuccess also guards SQLAllocHandle during statement construction, where the handle is not yet valid. Failing indiscriminately therefore leaves a half-constructed SqlStatement whose destructor cannot unwind. Use sourceLocation to fail only the call sites a test means to target — the function name of a real execution is ExecuteDirect / Execute / Prepare, never a constructor.
Parameters
hStmtThe statement handle being checked. A fake may ignore it.
sourceLocationWhere in the library the check is happening.
Returns
The error to inject, or std::nullopt to let the successful call through.

The documentation for this class was generated from the following file: