|
Lightweight 0.20260921.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. | |
| virtual std::optional< SqlErrorInfo > | NextConnectionFailure (SQLHDBC hDbc, std::source_location const &sourceLocation) |
| Decides whether the next connection-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 failing would leave a half-constructed SqlStatement whose destructor cannot release the handle; it therefore skips injection entirely while hStmt is still SQL_NULL_HSTMT. A fake may narrow further via sourceLocation — the function name of a real execution is ExecuteDirect / Execute / Prepare — but does not have to in order to be safe.| hStmt | The statement handle being checked, never SQL_NULL_HSTMT. A fake may ignore it. |
| sourceLocation | Where in the library the check is happening. |
std::nullopt to let the successful call through.
|
inlinevirtual |
Decides whether the next connection-handle check should fail.
The connection-side counterpart of NextFailure, consulted by detail::CheckOdbcConnectionCall for a call that the driver reported as successful on a SQLHDBC rather than a SQLHSTMT (e.g. a pre-connect attribute set). Returning an engaged optional makes the caller treat the call as failed, exactly as an injected NextFailure does for a statement check.
Defaults to never injecting, so a fake that predates connection-handle support and overrides only NextFailure keeps compiling and behaving exactly as before.
SqlConnection is still being constructed or is in the middle of tearing down its handle could leave the handle leaked or double-released.| hDbc | The connection handle being checked, never SQL_NULL_HDBC. A fake may ignore it. |
| sourceLocation | Where in the library the check is happening. |
std::nullopt to let the successful call through.