Store error vector and SQL state in DatabaseException#27
Open
fdcastel wants to merge 1 commit intoasfernandes:mainfrom
Open
Store error vector and SQL state in DatabaseException#27fdcastel wants to merge 1 commit intoasfernandes:mainfrom
fdcastel wants to merge 1 commit intoasfernandes:mainfrom
Conversation
DatabaseException now deep-copies the Firebird error vector (ISC error codes) and extracts the SQL state from the original status vector before the IStatus is reused. New public methods: - getErrors(): returns isc_arg_gds/isc_arg_number entries (terminated by isc_arg_end). String arguments are excluded to avoid dangling pointers. - getErrorCode(): returns the primary ISC error code, or 0. - getSqlState(): returns the SQL state string (e.g. 42000), or empty. This is a non-breaking, additive change. Existing code continues to work unchanged. Fixes asfernandes#24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Store error vector in DatabaseException
Fixes #24
Summary
DatabaseExceptionnow stores the Firebird error vector (ISC error codes) and SQL state from the original status vector, making them available for programmatic error handling.Previously,
DatabaseExceptiononly stored the formatted message string (viawhat()), discarding the raw error codes. This made it impossible to map Firebird errors to SQLSTATE codes — a requirement for ODBC drivers and other consumers that need structured error information.Changes
Exception.h#include <vector>.DatabaseExceptionconstructor now deep-copies the error vector and extracts the SQL state before theIStatusis reused.getErrors()— returns the error vector containingisc_arg_gdsandisc_arg_numberentries, terminated byisc_arg_end. String arguments are excluded to avoid dangling pointers (formatted text is already inwhat()).getErrorCode()— convenience that returns the primary ISC error code (firstisc_arg_gdsvalue), or0if none.getSqlState()— returns the SQL state string (e.g."42000") if present in the original status vector, or empty otherwise.errorVector_,sqlState_.Exception.cppcopyErrorVector()— walks the Firebird status vector and copies only safe numeric entries (isc_arg_gds,isc_arg_number), skipping string pointers that would dangle afterIStatusreuse.extractSqlState()— extracts theisc_arg_sql_statestring from the status vector while it is still valid.src/test/Exception.cpp(new)Seven test cases covering:
isc_arg_gdsentriesisc_arg_endgetErrorCode()returns the first GDS code from the vectorwhat()message is preservedBackward Compatibility
This is a non-breaking, additive change. Existing code that catches
DatabaseExceptionand useswhat()continues to work unchanged. The inheritedFbCppException(const std::string&)constructor still works — the new members are value-initialized (empty vector, empty string).