1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "odbc-error.h"
#include <compileTimeFormatter.h>
namespace AdHoc {
StreamWriterT('5') {
template<typename ... Pn>
static void write(stream & s, const SQLCHAR sqlstatus[6], const Pn & ... pn)
{
s.write(reinterpret_cast<const char *>(sqlstatus), 5);
StreamWriter::next(s, pn...);
}
};
}
AdHocFormatter(ODBCErrorWithInfo, "%?: %?: %5: \"%?\"");
AdHocFormatter(ODBCErrorInvalidHandle, "(%?) Invalid handle passed into function");
AdHocFormatter(ODBCErrorNoData, "(%?) No error data available for record");
AdHocFormatter(ODBCError, "Failed to get diagnostics for return code %?");
ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle)
{
SQLCHAR sqlstatus[6];
SQLINTEGER sqlerr;
SQLCHAR sqlerrmsg[12800];
SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, sizeof(sqlerrmsg), NULL);
switch (rc) {
case SQL_SUCCESS:
case SQL_SUCCESS_WITH_INFO:
msg = ODBCErrorWithInfo::get(err, sqlerr, sqlstatus, sqlerrmsg);
break;
case SQL_INVALID_HANDLE:
msg = ODBCErrorInvalidHandle::get(err);
break;
case SQL_NO_DATA:
msg = ODBCErrorNoData::get(err);
break;
case SQL_ERROR:
default:
msg = ODBCError::get(err);
break;
}
}
std::string
ODBC::Error::message() const throw()
{
return msg;
}
|