summaryrefslogtreecommitdiff
path: root/libodbcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libodbcpp')
-rw-r--r--libodbcpp/odbc-error.cpp25
-rw-r--r--libodbcpp/odbc-mock.cpp5
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()