]> git.ipfire.org Git - thirdparty/pdns.git/blame - modules/db2backend/DB2Exception.cc
Merge pull request #1968 from pieterlexis/port-faq
[thirdparty/pdns.git] / modules / db2backend / DB2Exception.cc
CommitLineData
092f210a 1// $Id$
92370e0a
BH
2
3#include "DB2Exception.hh"
4
5DB2Exception::DB2Exception(SQLRETURN inError)
6 : mError(inError), mHandle(SQL_NULL_HANDLE), mErrorIndex(1)
7{
8}
9
10DB2Exception::DB2Exception(SQLRETURN inError, SQLSMALLINT inHandleType, SQLHANDLE inHandle)
11 : mError(inError), mHandle(inHandle), mHandleType(inHandleType), mErrorIndex(1)
12{
13}
14
15SQLRETURN DB2Exception::GetError()
16{
17 return mError;
18}
19
20bool DB2Exception::GetNextSqlError(int& outNativeError, string& outSqlState, string& outSqlMessage)
21{
22 SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1];
23 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
24 SQLINTEGER sqlcode;
25 SQLSMALLINT length;
26
27 bool theResult = false;
28
29 if (mHandle != SQL_NULL_HANDLE)
30 {
31 SQLRETURN theError = SQLGetDiagRec(mHandleType, mHandle, mErrorIndex, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length);
32 if (theError == SQL_SUCCESS)
33 {
34 outNativeError = sqlcode;
35 outSqlState = (const char*) sqlstate;
36 outSqlMessage = (const char*) message;
37
38 mErrorIndex++;
39 theResult = true;
40 }
41 }
42
43 return theResult;
44}