From 41be9ec2da1cd559aa9d1e11c3bc31cfac637bd7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 31 Dec 2016 04:59:00 +0000 Subject: Do lots more work with compile time formatter instead runtime formatters --- libdbpp/column.cpp | 5 +++-- libdbpp/connection.cpp | 13 ++++++++----- libdbpp/mockDatabase.cpp | 5 +++-- libdbpp/selectcommand.cpp | 8 +++++--- libdbpp/sqlParse.ll | 5 +++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp index 2bb29d8..e7bbd21 100644 --- a/libdbpp/column.cpp +++ b/libdbpp/column.cpp @@ -1,7 +1,7 @@ #include "column.h" #include #include -#include +#include namespace DB { Column::Column(const Glib::ustring & n, unsigned int i) : @@ -16,10 +16,11 @@ Column::~Column() InvalidConversion::InvalidConversion(const char * const f, const char * const t) : from(f), to(t) { } +AdHocFormatter(InvalidConversionMsg, "Invalid conversion from column type (%?) to value type (%?)"); std::string InvalidConversion::message() const throw() { - return stringf("Invalid conversion from column type (%s) to value type (%s)", from, to); + return InvalidConversionMsg::get(from, to); } template diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 6d79bc2..98fc89b 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -3,7 +3,7 @@ #include "selectcommand.h" #include "error.h" #include -#include +#include #include #include #include @@ -55,11 +55,13 @@ DB::Connection::finish() const } } +AdHocFormatter(SavePointFmt, "tx_sp_%?_%?"); + void DB::Connection::beginTx() { if (inTx()) { - savepoint(stringbf("tx_sp_%p_%d", this, txOpenDepth)); + savepoint(SavePointFmt::get(this, txOpenDepth)); } else { beginTxInt(); @@ -77,7 +79,7 @@ DB::Connection::commitTx() commitTxInt(); break; default: - releaseSavepoint(stringbf("tx_sp_%p_%d", this, txOpenDepth - 1)); + releaseSavepoint(SavePointFmt::get(this, txOpenDepth - 1)); break; } txOpenDepth -= 1; @@ -93,7 +95,7 @@ DB::Connection::rollbackTx() rollbackTxInt(); break; default: - rollbackToSavepoint(stringbf("tx_sp_%p_%d", this, txOpenDepth - 1)); + rollbackToSavepoint(SavePointFmt::get(this, txOpenDepth - 1)); break; } txOpenDepth -= 1; @@ -181,10 +183,11 @@ DB::Connection::bulkUploadData(FILE * in) const } +AdHocFormatter(PluginLibraryFormat, "libdbpp-%?.so"); boost::optional DB::Connection::resolvePlugin(const std::type_info &, const std::string & name) { - return stringbf("libdbpp-%s.so", name); + return PluginLibraryFormat::get(name); } int64_t diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp index 52deb7e..8951189 100644 --- a/libdbpp/mockDatabase.cpp +++ b/libdbpp/mockDatabase.cpp @@ -1,5 +1,5 @@ #include "mockDatabase.h" -#include +#include #include #include #include @@ -68,10 +68,11 @@ MockDatabase::PlaySchemaScript(DB::Connection * conn, const boost::filesystem::p f.close(); } +AdHocFormatter(MockServerDatabaseName, "test_%?_%?"); MockServerDatabase::MockServerDatabase(const std::string & masterdb, const std::string & name, const std::string & type) : MockDatabase(name), master(DB::ConnectionFactory::createNew(type, masterdb)), - testDbName(stringbf("test_%d_%d", getpid(), ++mocked)) + testDbName(MockServerDatabaseName::get(getpid(), ++mocked)) { } diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp index 6f36aa5..fd0c58e 100644 --- a/libdbpp/selectcommand.cpp +++ b/libdbpp/selectcommand.cpp @@ -2,23 +2,25 @@ #include "error.h" #include #include -#include +#include namespace DB { ColumnIndexOutOfRange::ColumnIndexOutOfRange(unsigned int n) : colNo(n) { } + AdHocFormatter(ColumnIndexOutOfRangeMsg, "Column (%?) index out of range"); std::string ColumnIndexOutOfRange::message() const throw() { - return stringf("Column (%u) index out of range", colNo); + return ColumnIndexOutOfRangeMsg::get(colNo); } ColumnDoesNotExist::ColumnDoesNotExist(const Glib::ustring & n) : colName(n) { } + AdHocFormatter(ColumnDoesNotExistMsg, "Column (%?) does not exist"); std::string ColumnDoesNotExist::message() const throw() { - return stringf("Column (%s) does not exist", colName.c_str()); + return ColumnDoesNotExistMsg::get(colName); } }; diff --git a/libdbpp/sqlParse.ll b/libdbpp/sqlParse.ll index f33f311..3037c0a 100644 --- a/libdbpp/sqlParse.ll +++ b/libdbpp/sqlParse.ll @@ -9,7 +9,7 @@ %{ #include -#include +#include #include "sqlParse.h" #pragma GCC diagnostic ignored "-Wsign-compare" %} @@ -136,10 +136,11 @@ scriptdir "$SCRIPTDIR" namespace DB { SqlParseException::SqlParseException(const char * r, unsigned int l) : reason(r), line(l) { } + AdHocFormatter(SqlParseExceptionMsg, "Error parsing SQL script: %? at line %?"); std::string SqlParseException::message() const throw() { - return stringf("Error parsing SQL script: %s at line %u", reason, line); + return SqlParseExceptionMsg::get(reason, line); } SqlParse::SqlParse(std::istream & f, const boost::filesystem::path & s, Connection * c) : -- cgit v1.2.3