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 | |
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')
-rw-r--r-- | libodbcpp/odbc-error.cpp | 25 | ||||
-rw-r--r-- | libodbcpp/odbc-mock.cpp | 5 |
2 files changed, 23 insertions, 7 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; } } diff --git a/libodbcpp/odbc-mock.cpp b/libodbcpp/odbc-mock.cpp index 2799fb3..0ab6ee6 100644 --- a/libodbcpp/odbc-mock.cpp +++ b/libodbcpp/odbc-mock.cpp @@ -1,6 +1,6 @@ #include "odbc-connection.h" #include "odbc-mock.h" -#include <buffer.h> +#include <compileTimeFormatter.h> namespace ODBC { @@ -12,10 +12,11 @@ Mock::Mock(const std::string & b, const std::string & masterdb, const std::strin PlaySchemaScripts(ss); } +AdHocFormatter(MockConnStr, "%?;Database=%?"); DB::Connection * Mock::openConnection() const { - return new Connection(stringbf("%s;Database=%s", base, testDbName)); + return new Connection(MockConnStr::get(base, testDbName)); } Mock::~Mock() |