A class holding the information of a complete diagnostic. More...
#include <diagnostic.h>
Public Member Functions | |
diagnostic (SQLSMALLINT handle_type, SQLHANDLE hdl, handle *parent=0) | |
Initializes a diagnostic object from a handle. | |
diagnostic (SQLINTEGER odbcpp_errno, const std::string &message) | |
Initializes a diagnostic object with a simple message. | |
diagnostic () | |
Create an empty diagnostic object. | |
diag_t | get (SQLSMALLINT record) const |
Get the specified diagnostic record. | |
SQLLEN | get_affected_rows () const |
Retrieve the number of affected rows. | |
std::string | msg () const |
Retrieve a complete error message. | |
diag_t | operator[] (int record) const |
Retrives the specified diagnostic. | |
void | set (SQLSMALLINT handle_type, SQLHANDLE handle) |
Initializes a diagnostic object from a handle. | |
SQLSMALLINT | size () const |
Returns the number of records defined in this diagnostic. | |
Static Public Member Functions | |
static bool | get_integer (SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, SQLSMALLINT identifier, SQLINTEGER &integer) |
Get a diagnostic integer. | |
static bool | get_length (SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, SQLSMALLINT identifier, SQLLEN &length) |
Get a diagnostic length. | |
static bool | get_string (SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, SQLSMALLINT identifier, std::string &string) |
Get a diagnostic string. | |
Private Attributes | |
SQLLEN | f_affected_rows |
Holds the number of rows that were affected by the last SQL command. | |
diag_vector_t | f_diag |
The array of diagnostics. |
A class holding the information of a complete diagnostic.
This class is used to read the diagnostics from a handle after a function was called on that handle. In general that happens after calling the handle::check() function and just before throwing an exception.
This diagnostic will be saved in the odbcpp_error object.
Definition at line 55 of file diagnostic.h.
odbcpp::diagnostic::diagnostic | ( | ) | [inline] |
Create an empty diagnostic object.
This constructor initialize an empty diagnostic object.
You can later set an error by calling the set() function.
Definition at line 58 of file diagnostic.h.
odbcpp::diagnostic::diagnostic | ( | SQLINTEGER | odbcpp_errno, | |
const std::string & | message | |||
) |
Initializes a diagnostic object with a simple message.
Some odbcpp functions do not have access to any handle and whenever they need to generate a diagnostic for an exception, it uses this constructor with a message.
[in] | odbcpp_errno | One of the odbcpp errors |
[in] | message | An error message |
Definition at line 191 of file diagnostic.cpp.
References f_diag, odbcpp::diag_t::f_message, odbcpp::diag_t::f_native_errno, and odbcpp::diag_t::f_odbc_state.
odbcpp::diagnostic::diagnostic | ( | SQLSMALLINT | handle_type, | |
SQLHANDLE | hdl, | |||
handle * | parent = 0 | |||
) |
Initializes a diagnostic object from a handle.
This constructor queries the specified handle for the error messages and numbers as available in the diag_t structure.
[in] | handle_type | The SQL type of handle |
[in] | hdl | The SQL handle to query |
[in] | parent | The parent handle when allocating a handle |
Definition at line 216 of file diagnostic.cpp.
References f_diag, odbcpp::diag_t::f_message, odbcpp::diag_t::f_native_errno, odbcpp::diag_t::f_odbc_state, odbcpp::handle::get_handle(), odbcpp::handle::get_handle_type(), and odbcpp::odbcpp_error::ODBCPP_INTERNAL.
odbcpp::diagnostic::get | ( | SQLSMALLINT | record | ) | const [inline] |
Get the specified diagnostic record.
Retrieve a diag_t object with the specified record number.
Note that the record numbers start at 1 and go on up to size() inclusive.
std::runtime_error | This function will throw an exception if the requested record does not exist. |
[in] | record | A record number from 1 to size() inclusive |
Definition at line 67 of file diagnostic.h.
References f_diag.
odbcpp::diagnostic::get_affected_rows | ( | ) | const [inline] |
Retrieve the number of affected rows.
Whenever an SQL command is executed, it affects a certain number of rows. This is saved in an ODBC variable read by the diagnostic object. The saved data can later be retrieved with this function.
This number can be zero if there was no match.
Definition at line 65 of file diagnostic.h.
References f_affected_rows.
bool odbcpp::diagnostic::get_integer | ( | SQLSMALLINT | handle_type, | |
SQLHANDLE | handle, | |||
SQLSMALLINT | record, | |||
SQLSMALLINT | identifier, | |||
SQLINTEGER & | integer | |||
) | [static] |
Get a diagnostic integer.
This function retrieves an integer from the specified handle.
This function should be called after a call to any SQL function other than diagnostic functions.
integer
parameter is automatically set to 0 by default. If the function fails, you will get zero.[in] | handle_type | A valid SQL handle type |
[in] | handle | A valid SQL handle |
[in] | record | The record number starting at 1 |
[in] | identifier | The identifier to be retrieved; must be a string |
[out] | integer | Where to put the resulting query |
Definition at line 455 of file diagnostic.cpp.
References size().
Referenced by set().
bool odbcpp::diagnostic::get_length | ( | SQLSMALLINT | handle_type, | |
SQLHANDLE | handle, | |||
SQLSMALLINT | record, | |||
SQLSMALLINT | identifier, | |||
SQLLEN & | length | |||
) | [static] |
Get a diagnostic length.
This function retrieves a diagnostic length from the specified handle.
This function should be called after a call to any SQL function other than diagnostic functions.
length
parameter is automatically set to 0 by default. If the function fails, you will get zero.[in] | handle_type | A valid SQL handle type |
[in] | handle | A valid SQL handle |
[in] | record | The record number starting at 1 |
[in] | identifier | The identifier to be retrieved; must be an SQLLEN variable |
[out] | length | Where to put the resulting query |
Definition at line 507 of file diagnostic.cpp.
References size().
Referenced by set().
bool odbcpp::diagnostic::get_string | ( | SQLSMALLINT | handle_type, | |
SQLHANDLE | handle, | |||
SQLSMALLINT | record, | |||
SQLSMALLINT | identifier, | |||
std::string & | string | |||
) | [static] |
Get a diagnostic string.
This function retrieves a string from the specified handle.
This function should be called after a call to any SQL function other than diagnostic functions.
string
parameter is automatically set to "" by default. If the function fails, you will get an empty string.[in] | handle_type | A valid SQL handle type |
[in] | handle | A valid SQL handle |
[in] | record | The record number starting at 1 |
[in] | identifier | The identifier to be retrieved; must be a string |
[out] | string | Where to put the resulting query |
Definition at line 397 of file diagnostic.cpp.
References size().
Referenced by set().
std::string odbcpp::diagnostic::msg | ( | ) | const |
Retrieve a complete error message.
This function generates a complete error message from the set of diagnostics. This can be huge.
Definition at line 313 of file diagnostic.cpp.
odbcpp::diagnostic::operator[] | ( | int | record | ) | const [inline] |
Retrives the specified diagnostic.
Retrieve a diag_t object with the specified record number.
Note that the record numbers start at 1 and go on up to size() inclusive.
std::runtime_error | This function will throw an exception if the requested record does note exist. |
[in] | record | A record number from 1 to size() inclusive |
Definition at line 68 of file diagnostic.h.
References f_diag.
void odbcpp::diagnostic::set | ( | SQLSMALLINT | handle_type, | |
SQLHANDLE | handle | |||
) |
Initializes a diagnostic object from a handle.
This function queries the specified handle for the error messages and numbers as available in the diag_t structure.
[in] | handle_type | The SQL type of handle |
[in] | handle | The SQL handle to query |
Definition at line 274 of file diagnostic.cpp.
References f_affected_rows, odbcpp::diag_t::f_connection, f_diag, odbcpp::diag_t::f_message, odbcpp::diag_t::f_native_errno, odbcpp::diag_t::f_odbc_state, odbcpp::diag_t::f_server, get_integer(), get_length(), and get_string().
odbcpp::diagnostic::size | ( | ) | const [inline] |
Returns the number of records defined in this diagnostic.
This function returns the number of record defined in this diagnostic.
The number of records can be zero.
Definition at line 66 of file diagnostic.h.
References f_diag.
Referenced by get_integer(), get_length(), get_string(), and msg().
odbcpp::diagnostic::f_affected_rows [private] |
Holds the number of rows that were affected by the last SQL command.
This variable is used to retrieve the number of affected rows whenever a diagnostic is created. This number can be zero when no row matched a WHERE clause.
Definition at line 75 of file diagnostic.h.
Referenced by get_affected_rows(), and set().
odbcpp::diagnostic::f_diag [private] |
The array of diagnostics.
This variable holds all the diag_t that were found in the handle specified on the constructor of the diagnostic object.
If only an error code and message were specified, then this array has one entry.
Use the size() function to retrive the size and the get() or operator [] to retrieve the content.
Definition at line 76 of file diagnostic.h.
Referenced by diagnostic(), get(), msg(), operator[](), set(), and size().