|
Lightweight 0.20260625.0
|
Substitutes a scripted failure for an ODBC call that actually succeeded. More...
#include <Utils.hpp>
Public Member Functions | |
| SqlFaultSource (SqlFaultSource const &)=delete | |
| SqlFaultSource & | operator= (SqlFaultSource const &)=delete |
| SqlFaultSource (SqlFaultSource &&)=delete | |
| SqlFaultSource & | operator= (SqlFaultSource &&)=delete |
| virtual std::optional< SqlErrorInfo > | NextFailure (SQLHSTMT hStmt, std::source_location const &sourceLocation)=0 |
| Decides whether the next statement-handle check should fail. | |
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.
|
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.
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.| hStmt | The statement handle being checked. A fake may ignore it. |
| sourceLocation | Where in the library the check is happening. |
std::nullopt to let the successful call through.