diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-31 04:59:00 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-31 04:59:00 +0000 |
commit | cadf2251ea3fa4f651726223e5426703f9a94a62 (patch) | |
tree | 6e3cec26902b34198d03494f12a10648cc8b7b70 /libodbcpp/odbc-error.cpp | |
parent | Set cxxflags specifically, not cflags (diff) | |
download | libdbpp-odbc-cadf2251ea3fa4f651726223e5426703f9a94a62.tar.bz2 libdbpp-odbc-cadf2251ea3fa4f651726223e5426703f9a94a62.tar.xz libdbpp-odbc-cadf2251ea3fa4f651726223e5426703f9a94a62.zip |
Do lots more work with compile time formatter instead runtime formatters
Diffstat (limited to 'libodbcpp/odbc-error.cpp')
-rw-r--r-- | libodbcpp/odbc-error.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/libodbcpp/odbc-error.cpp b/libodbcpp/odbc-error.cpp index db677db..4f8f89a 100644 --- a/libodbcpp/odbc-error.cpp +++ b/libodbcpp/odbc-error.cpp @@ -1,6 +1,21 @@ #include "odbc-error.h" -#include <buffer.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]; @@ -11,20 +26,20 @@ ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle) switch (rc) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - msg = stringbf("%d: %d: %5.5s: \"%s\"", err, (int)sqlerr, sqlstatus, sqlerrmsg); + msg = ODBCErrorWithInfo::get(err, sqlerr, sqlstatus, sqlerrmsg); break; case SQL_INVALID_HANDLE: - msg = stringbf("(%d) Invalid handle passed into function", err); + msg = ODBCErrorInvalidHandle::get(err); break; case SQL_NO_DATA: - msg = stringbf("(%d) No error data available for record", err); + msg = ODBCErrorNoData::get(err); break; case SQL_ERROR: default: - msg = stringbf("Failed to get diagnostics for return code %d", err); + msg = ODBCError::get(err); break; } } |