Public Types | Public Member Functions | Public Attributes

OCIPL::OciException Struct Reference

OCI Error handling. More...

#include <ocipl.h>

Inheritance diagram for OCIPL::OciException:
Inheritance graph
[legend]
Collaboration diagram for OCIPL::OciException:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::exception super

Public Member Functions

 OciException (OCIEnv *envh, const char *file, int line)
 OciException (OCIError *errh, const char *file, int line)
 OciException (const char *msg, const char *file, int line)
 OciException (OCIError *errh, SqlStatement &stmt, const char *file, int line)
 OciException (const OciException &)
 ~OciException () throw ()
virtual const char * what () const throw ()

Public Attributes

int _sql_error_code
char * _msg
const char * _file
int _line
tstring _last_sql
ub2 _parse_offset

Detailed Description

OCI Error handling.

Definition at line 304 of file ocipl.h.


Member Typedef Documentation

typedef std::exception OCIPL::OciException::super

Definition at line 306 of file ocipl.h.


Constructor & Destructor Documentation

OCIPL::OciException::OciException ( OCIEnv *  envh,
const char *  file,
int  line 
)

Definition at line 136 of file ocipl.cpp.

References _file, _line, _msg, _parse_offset, _sql_error_code, COUNTOF, and max_strdup().

{
    OraText buffer[1024];

    sb4 errorcode;
    sword res = OCIErrorGet(envh, 1, NULL, &errorcode, buffer, sizeof(buffer), OCI_HTYPE_ENV);

    if (res == OCI_SUCCESS) {
        _sql_error_code = errorcode;
        _msg = max_strdup((const char*)buffer, COUNTOF(buffer));
    } else {
        _sql_error_code = 0;
        _msg = NULL;
    }

    _file = file;
    _line = line;
    _parse_offset = 0;
}

Here is the call graph for this function:

OCIPL::OciException::OciException ( OCIError *  errh,
const char *  file,
int  line 
)

Definition at line 156 of file ocipl.cpp.

References _file, _line, _msg, _parse_offset, _sql_error_code, _tcslen, COUNTOF, max_strdup(), and TCHAR.

{
    TCHAR buffer[1024];

    sb4 errorcode;
    sword res = OCIErrorGet(errh, 1, NULL, &errorcode, (OraText*)buffer, sizeof(buffer), OCI_HTYPE_ERROR);

    if (res == OCI_SUCCESS) {
        _sql_error_code = errorcode;
#ifdef _UNICODE
        char nbuffer[2048];
#ifdef _MSC_VER
        std::_USE(std::locale::empty(), std::ctype<wchar_t>)
#else
        std::use_facet<std::ctype<wchar_t> >(std::locale::empty())
#endif
                .narrow((const TCHAR*)buffer, (const TCHAR*)buffer+_tcslen((const TCHAR*)buffer)+1, 0, nbuffer);
        _msg = max_strdup(nbuffer, COUNTOF(nbuffer));
#else
        _msg = max_strdup(buffer, COUNTOF(buffer));
#endif
    } else {
        _sql_error_code = 0;
        _msg = NULL;
    }

    _file = file;
    _line = line;
    _parse_offset = 0;
}

Here is the call graph for this function:

OCIPL::OciException::OciException ( const char *  msg,
const char *  file,
int  line 
)

Definition at line 291 of file ocipl.cpp.

References _file, _line, _msg, _sql_error_code, and _strdup.

{
    _msg = _strdup(msg);
    _file = file;
    _line = line;
    _sql_error_code = 0;
}
OCIPL::OciException::OciException ( OCIError *  errh,
SqlStatement stmt,
const char *  file,
int  line 
)

Definition at line 187 of file ocipl.cpp.

References _file, _last_sql, _line, _msg, _parse_offset, _snprintf, _sql_error_code, _tcslen, COUNTOF, OCIPL::SqlStatement::get_last_file(), OCIPL::SqlStatement::get_last_line(), OCIPL::SqlStatement::get_last_sql(), max_strdup(), max_strlen(), and TCHAR.

{
    char buffer[4096];

    sb4 errorcode;
#ifdef _UNICODE
    TCHAR wbuffer[4096];

    sword res = OCIErrorGet(errh, 1, NULL, &errorcode, (OraText*)wbuffer, sizeof(wbuffer), OCI_HTYPE_ERROR);

#ifdef _MSC_VER
        std::_USE(std::locale::empty(), std::ctype<wchar_t>)
#else
        std::use_facet<std::ctype<wchar_t> >(std::locale::empty())
#endif
                .narrow((const TCHAR*)wbuffer, (const TCHAR*)wbuffer+_tcslen((const TCHAR*)wbuffer)+1, 0, buffer);
#else
    sword res = OCIErrorGet(errh, 1, NULL, &errorcode, (OraText*)buffer, sizeof(buffer), OCI_HTYPE_ERROR);
#endif

    ub4 size = sizeof(_parse_offset);
    if (OCIAttrGet(stmt, OCI_HTYPE_STMT, &_parse_offset, &size, OCI_ATTR_PARSE_ERROR_OFFSET, errh) != OCI_SUCCESS)
        _parse_offset = 0;

    if (res == OCI_SUCCESS)
        _sql_error_code = errorcode;
    else {
        *buffer = '\0';
        _sql_error_code = 0;
    }

    _last_sql = stmt.get_last_sql();

    _file = file;
    _line = line;

    if (!_last_sql.empty()) {
        file = stmt.get_last_file();

         // copy source code position from statement if available
        if (file) {
            _file = file;
            _line = stmt.get_last_line();
        }

        const TCHAR* sql = _last_sql.c_str();
        size_t l = max_strlen(buffer, COUNTOF(buffer));

        int line = 1;
        const TCHAR* s = sql;
        const TCHAR* e = sql + _parse_offset;
        const TCHAR* lp = sql;

        while(s < e)
            if (*s == '\n') {
                ++line;

                if (*++s == '\r')
                    ++s;

                lp = s;
            } else
                ++s;

        int column = 1 + (s-lp);

#ifdef __STDC_WANT_SECURE_LIB__
        char* b = buffer+l + _snprintf_s(buffer+l, sizeof(buffer)-l, _TRUNCATE, "\nerror at SQL position %d [%d.%d]:\n", _parse_offset, line, column);
#else
        char* b = buffer+l + _snprintf(buffer+l, sizeof(buffer)-l-1, "\nerror at SQL position %d [%d.%d]:\n", _parse_offset, line, column);
#endif
        char* p = b;
        s = lp;
        while(*s && *s!='\n' && p<buffer+sizeof(buffer)-3)
            *p++ = *s++;

        *p++ = '\n';

        b = p;
        const TCHAR* err_ptr = sql + _parse_offset;
        s = lp;
        for(; s<err_ptr && p<buffer+sizeof(buffer)-2; ++s) {
            if (*s=='\n' || *sql=='\r')
                p = b;
            else if (*s == '\t')
                *p++ = '\t';
            else
                *p++ = ' ';
        }

        *p++ = '^';
        *p = '\0';

        l = max_strlen(buffer, COUNTOF(buffer));
#ifdef __STDC_WANT_SECURE_LIB__
        _snprintf_s(buffer+l, sizeof(buffer)-l, _TRUNCATE, "\n\nlast SQL statement:\n%s", sql);
#else
        _snprintf(buffer+l, sizeof(buffer)-l, "\n\nlast SQL statement:\n%s", sql);
#endif
    }

    _msg = max_strdup(buffer, COUNTOF(buffer));
}

Here is the call graph for this function:

OCIPL::OciException::OciException ( const OciException other )

Definition at line 299 of file ocipl.cpp.

References _file, _last_sql, _line, _msg, _sql_error_code, and _strdup.

{
    _sql_error_code = other._sql_error_code;
    _msg = _strdup(other._msg);
    _file = other._file;
    _line = other._line;
    _last_sql = other._last_sql;
}
OCIPL::OciException::~OciException (  ) throw ()

Definition at line 309 of file ocipl.cpp.

References _msg.

{
    free(_msg);
}

Member Function Documentation

virtual const char* OCIPL::OciException::what (  ) const throw () [inline, virtual]

Definition at line 317 of file ocipl.h.

References _msg.

    {
        return _msg;
    }

Member Data Documentation

Definition at line 324 of file ocipl.h.

Referenced by OciException().

Definition at line 326 of file ocipl.h.

Referenced by OciException().

Definition at line 325 of file ocipl.h.

Referenced by OciException().

Definition at line 323 of file ocipl.h.

Referenced by OciException(), what(), and ~OciException().

Definition at line 327 of file ocipl.h.

Referenced by OciException().

Definition at line 322 of file ocipl.h.

Referenced by OciException().


The documentation for this struct was generated from the following files: