Made to Order Software Corporation Logo

odbcpp: odbcpp::diagnostic Class Reference

A class holding the information of a complete diagnostic. More...

#include <diagnostic.h>

Collaboration diagram for odbcpp::diagnostic:

List of all members.

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.


Detailed Description

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.

See also:
odbcpp_error

Definition at line 55 of file diagnostic.h.


Constructor & Destructor Documentation

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.

See also:
set()

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.

Parameters:
[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.

Parameters:
[in] handle_type The SQL type of handle
[in] hdl The SQL handle to query
[in] parent The parent handle when allocating a handle
See also:
set()

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.


Member Function Documentation

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.

Exceptions:
std::runtime_error This function will throw an exception if the requested record does not exist.
Parameters:
[in] record A record number from 1 to size() inclusive
Returns:
a copy of the diag_t at the specified position

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.

Returns:
The number of rows that were selected, updated, deleted, inserted.

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.

Note:
The integer parameter is automatically set to 0 by default. If the function fails, you will get zero.
Parameters:
[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
Returns:
true if the integer was properly retrieved.

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.

Note:
The length parameter is automatically set to 0 by default. If the function fails, you will get zero.
Parameters:
[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
Returns:
true if the integer was properly retrieved.

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.

Note:
The string parameter is automatically set to "" by default. If the function fails, you will get an empty string.
Parameters:
[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
Returns:
true if the string was properly retrieved.

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.

Returns:
a string with the message

Definition at line 313 of file diagnostic.cpp.

References f_diag, and size().

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.

Exceptions:
std::runtime_error This function will throw an exception if the requested record does note exist.
Parameters:
[in] record A record number from 1 to size() inclusive
Returns:
a copy of the diag_t at the specified position

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.

Parameters:
[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.

Returns:
The number of record defined in this diagnostic

Definition at line 66 of file diagnostic.h.

References f_diag.

Referenced by get_integer(), get_length(), get_string(), and msg().


Member Data Documentation

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().

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.

See also:
size()
get()

Definition at line 76 of file diagnostic.h.

Referenced by diagnostic(), get(), msg(), operator[](), set(), and size().


The documentation for this class was generated from the following files:
Generated on Mon Sep 19 12:52:27 2011 for odbcpp by  doxygen 1.6.3