From 881033464c13398f78be306d8d785616f0947896 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 24 Feb 2019 15:29:12 +0000 Subject: Bring inline with clang-tidy checks --- libodbcpp/odbc-bind.cpp | 11 --------- libodbcpp/odbc-bind.h | 3 +-- libodbcpp/odbc-column.cpp | 28 +++++++++++++--------- libodbcpp/odbc-column.h | 2 +- libodbcpp/odbc-command.cpp | 10 +------- libodbcpp/odbc-command.h | 6 ++--- libodbcpp/odbc-connection.cpp | 27 +++++++++++---------- libodbcpp/odbc-dsn.cpp | 12 ++++------ libodbcpp/odbc-dsn.h | 4 ++-- libodbcpp/odbc-error.cpp | 5 ++-- libodbcpp/odbc-error.h | 2 +- libodbcpp/odbc-mock.cpp | 4 ++-- libodbcpp/odbc-modifycommand.cpp | 4 ---- libodbcpp/odbc-modifycommand.h | 1 - libodbcpp/odbc-param.cpp | 36 ++++++++++++++-------------- libodbcpp/odbc-param.h | 52 +++++++++++++--------------------------- libodbcpp/odbc-param_fwd.h | 29 ++++++++++++++++++++++ libodbcpp/odbc-selectcommand.cpp | 10 ++++---- libodbcpp/unittests/testodbc.cpp | 2 +- 19 files changed, 118 insertions(+), 130 deletions(-) delete mode 100644 libodbcpp/odbc-bind.cpp create mode 100644 libodbcpp/odbc-param_fwd.h diff --git a/libodbcpp/odbc-bind.cpp b/libodbcpp/odbc-bind.cpp deleted file mode 100644 index 1575fd0..0000000 --- a/libodbcpp/odbc-bind.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "odbc-bind.h" - -ODBC::Bind::Bind() -{ -} - -ODBC::Bind::~Bind() -{ -} - - diff --git a/libodbcpp/odbc-bind.h b/libodbcpp/odbc-bind.h index 356723b..7a982e6 100644 --- a/libodbcpp/odbc-bind.h +++ b/libodbcpp/odbc-bind.h @@ -7,8 +7,7 @@ namespace ODBC { class Bind { public: - Bind(); - virtual ~Bind() = 0; + virtual ~Bind() = default; virtual SQLSMALLINT ctype() const = 0; // The C type ID virtual SQLULEN size() const = 0; // The size of the data diff --git a/libodbcpp/odbc-column.cpp b/libodbcpp/odbc-column.cpp index f51aad5..2a25f9b 100644 --- a/libodbcpp/odbc-column.cpp +++ b/libodbcpp/odbc-column.cpp @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include "odbc-column.h" #include "odbc-command.h" #include "odbc-selectcommand.h" @@ -13,10 +13,6 @@ ODBC::Column::Column(SelectCommand * sc, const Glib::ustring & s, unsigned int i bindLen = 0; } -ODBC::Column::~Column() -{ -} - bool ODBC::Column::resize() { @@ -69,30 +65,40 @@ ODBC::IntervalColumn::operator boost::posix_time::time_duration() const void ODBC::SignedIntegerColumn::apply(DB::HandleField & h) const { - if (isNull()) return h.null(); + if (isNull()) { + return h.null(); + } h.integer(data); } void ODBC::FloatingPointColumn::apply(DB::HandleField & h) const { - if (isNull()) return h.null(); + if (isNull()) { + return h.null(); + } h.floatingpoint(data); } void ODBC::CharArrayColumn::apply(DB::HandleField & h) const { - if (isNull()) return h.null(); + if (isNull()) { + return h.null(); + } h.string({ data.data(), (std::size_t)bindLen }); } void ODBC::TimeStampColumn::apply(DB::HandleField & h) const { - if (isNull()) return h.null(); + if (isNull()) { + return h.null(); + } h.timestamp(*this); } void ODBC::IntervalColumn::apply(DB::HandleField & h) const { - if (isNull()) return h.null(); + if (isNull()) { + return h.null(); + } h.interval(*this); } diff --git a/libodbcpp/odbc-column.h b/libodbcpp/odbc-column.h index b914793..85f1b97 100644 --- a/libodbcpp/odbc-column.h +++ b/libodbcpp/odbc-column.h @@ -13,7 +13,7 @@ namespace ODBC { class Column : public virtual Bind, public virtual DB::Column { public: Column(SelectCommand *, const Glib::ustring & s, unsigned int i); - virtual ~Column() = 0; + virtual ~Column() = default; void bind(); virtual void * rwDataAddress() = 0; virtual bool resize(); diff --git a/libodbcpp/odbc-command.cpp b/libodbcpp/odbc-command.cpp index 43572c8..34febf3 100644 --- a/libodbcpp/odbc-command.cpp +++ b/libodbcpp/odbc-command.cpp @@ -5,6 +5,7 @@ ODBC::Command::Command(const Connection & c, const std::string & s) : DB::Command(s), + hStmt(nullptr), connection(c) { RETCODE rc = SQLAllocHandle(SQL_HANDLE_STMT, c.conn, &hStmt); @@ -29,12 +30,3 @@ ODBC::Command::Command(const Connection & c, const std::string & s) : params.resize(pcount); } -ODBC::Command::~Command() -{ - for (Params::iterator i = params.begin(); i != params.end(); ++i) { - if (*i) { - delete *i; - } - } -} - diff --git a/libodbcpp/odbc-command.h b/libodbcpp/odbc-command.h index a3a4338..ceba2dc 100644 --- a/libodbcpp/odbc-command.h +++ b/libodbcpp/odbc-command.h @@ -4,15 +4,15 @@ #include #include #include "odbc-connection.h" +#include "odbc-param_fwd.h" #include namespace ODBC { - class Param; + using ParamPtr = std::unique_ptr; class Command : public virtual DB::Command { - typedef std::vector Params; + using Params = std::vector; public: Command(const Connection &, const std::string & sql); - virtual ~Command() = 0; void bindParamI(unsigned int i, int val) override; void bindParamI(unsigned int i, long val) override; diff --git a/libodbcpp/odbc-connection.cpp b/libodbcpp/odbc-connection.cpp index 9a4a82d..4e4a0a1 100644 --- a/libodbcpp/odbc-connection.cpp +++ b/libodbcpp/odbc-connection.cpp @@ -1,7 +1,7 @@ #include #include -#include -#include +#include +#include #include "odbc-connection.h" #include "odbc-selectcommand.h" #include "odbc-modifycommand.h" @@ -10,8 +10,8 @@ NAMEDFACTORY("odbc", ODBC::Connection, DB::ConnectionFactory); ODBC::Connection::Connection(const DSN& d) : - env(0), - conn(0), + env(nullptr), + conn(nullptr), thinkDelStyle(DB::BulkDeleteUsingUsing), thinkUpdStyle(DB::BulkUpdateUsingFromSrc) { @@ -56,25 +56,26 @@ ODBC::Connection::connectPost() throw ConnectionError(dberr, SQL_HANDLE_DBC, conn); } char info[1024]; - dberr = SQLGetInfo(conn, SQL_DRIVER_NAME, (SQLCHAR*)info, sizeof(info), NULL); + dberr = SQLGetInfo(conn, SQL_DRIVER_NAME, (SQLCHAR*)info, sizeof(info), nullptr); if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_DBC, conn); } // Apply known DB specific tweaks - if (strstr(info, "myodbc") != NULL) { + // NOLINTNEXTLINE(hicpp-no-array-decay) + if (strstr(info, "myodbc")) { thinkDelStyle = DB::BulkDeleteUsingUsingAlias; thinkUpdStyle = DB::BulkUpdateUsingJoin; } } ODBC::Connection::Connection(const std::string & s) : - env(0), - conn(0), + env(nullptr), + conn(nullptr), thinkDelStyle(DB::BulkDeleteUsingUsing), thinkUpdStyle(DB::BulkUpdateUsingFromSrc) { connectPre(); - RETCODE dberr = SQLDriverConnect(conn, NULL, (SQLCHAR*)s.c_str(), s.length(), NULL, 0, NULL, SQL_DRIVER_NOPROMPT); + RETCODE dberr = SQLDriverConnect(conn, nullptr, (SQLCHAR*)s.c_str(), s.length(), nullptr, 0, nullptr, SQL_DRIVER_NOPROMPT); if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_DBC, conn); } @@ -84,11 +85,11 @@ ODBC::Connection::Connection(const std::string & s) : ODBC::Connection::~Connection() { if (conn) { - SQL_SUCCEEDED(SQLDisconnect(conn)); - SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_DBC, conn)); + SQLDisconnect(conn); + SQLFreeHandle(SQL_HANDLE_DBC, conn); } if (env) { - SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_ENV, env)); + SQLFreeHandle(SQL_HANDLE_ENV, env); } } @@ -169,7 +170,7 @@ SQLINTEGER ODBC::Connection::getAttrInt(SQLINTEGER attr) const { SQLINTEGER result; - SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, &result, sizeof(result), 0); + SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, &result, sizeof(result), nullptr); if (!SQL_SUCCEEDED(dberr)) { throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn); } diff --git a/libodbcpp/odbc-dsn.cpp b/libodbcpp/odbc-dsn.cpp index 766b0ac..d2802bd 100644 --- a/libodbcpp/odbc-dsn.cpp +++ b/libodbcpp/odbc-dsn.cpp @@ -1,13 +1,9 @@ #include "odbc-dsn.h" -ODBC::DSN::DSN(const std::string & d, const std::string & u, const std::string & p) : - dsn(d), - username(u), - password(p) -{ -} - -ODBC::DSN::~DSN() +ODBC::DSN::DSN(std::string d, std::string u, std::string p) : + dsn(std::move(d)), + username(std::move(u)), + password(std::move(p)) { } diff --git a/libodbcpp/odbc-dsn.h b/libodbcpp/odbc-dsn.h index 6be7e3b..4568cb6 100644 --- a/libodbcpp/odbc-dsn.h +++ b/libodbcpp/odbc-dsn.h @@ -6,8 +6,8 @@ namespace ODBC { class DSN { public: - DSN(const std::string &, const std::string &, const std::string &); - virtual ~DSN(); + DSN(std::string, std::string, std::string); + virtual ~DSN() = default; const std::string dsn; // DSN name for odbc.ini const std::string username; // User name const std::string password; // Password diff --git a/libodbcpp/odbc-error.cpp b/libodbcpp/odbc-error.cpp index 4f8f89a..7179a17 100644 --- a/libodbcpp/odbc-error.cpp +++ b/libodbcpp/odbc-error.cpp @@ -22,7 +22,8 @@ ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle) SQLINTEGER sqlerr; SQLCHAR sqlerrmsg[12800]; - SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, sizeof(sqlerrmsg), NULL); + // NOLINTNEXTLINE(hicpp-no-array-decay) + SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, sizeof(sqlerrmsg), nullptr); switch (rc) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: @@ -45,7 +46,7 @@ ODBC::Error::Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle) } std::string -ODBC::Error::message() const throw() +ODBC::Error::message() const noexcept { return msg; } diff --git a/libodbcpp/odbc-error.h b/libodbcpp/odbc-error.h index fb9412c..addc528 100644 --- a/libodbcpp/odbc-error.h +++ b/libodbcpp/odbc-error.h @@ -11,7 +11,7 @@ namespace ODBC { public: Error(RETCODE err, SQLSMALLINT handletype, SQLHANDLE handle); - std::string message() const throw() override; + std::string message() const noexcept override; private: std::string msg; diff --git a/libodbcpp/odbc-mock.cpp b/libodbcpp/odbc-mock.cpp index f8386e7..29a9278 100644 --- a/libodbcpp/odbc-mock.cpp +++ b/libodbcpp/odbc-mock.cpp @@ -8,7 +8,7 @@ Mock::Mock(const std::string & b, const std::string & masterdb, const std::strin MockServerDatabase(b + ";" + masterdb, name, "odbc"), base(b) { - CreateNewDatabase(); + Mock::CreateNewDatabase(); PlaySchemaScripts(ss); } @@ -21,7 +21,7 @@ Mock::openConnection() const Mock::~Mock() { - DropDatabase(); + Mock::DropDatabase(); } void Mock::DropDatabase() const diff --git a/libodbcpp/odbc-modifycommand.cpp b/libodbcpp/odbc-modifycommand.cpp index 60bb7c4..3bea818 100644 --- a/libodbcpp/odbc-modifycommand.cpp +++ b/libodbcpp/odbc-modifycommand.cpp @@ -8,10 +8,6 @@ ODBC::ModifyCommand::ModifyCommand(const ODBC::Connection & c, const std::string { } -ODBC::ModifyCommand::~ModifyCommand() -{ -} - unsigned int ODBC::ModifyCommand::execute(bool anc) { diff --git a/libodbcpp/odbc-modifycommand.h b/libodbcpp/odbc-modifycommand.h index 796ee2f..3993d63 100644 --- a/libodbcpp/odbc-modifycommand.h +++ b/libodbcpp/odbc-modifycommand.h @@ -8,7 +8,6 @@ namespace ODBC { class ModifyCommand : public Command, public DB::ModifyCommand { public: ModifyCommand(const Connection &, const std::string & sql); - ~ModifyCommand(); // Execute the command and return effected row count unsigned int execute(bool allowNoChange = true) override; }; diff --git a/libodbcpp/odbc-param.cpp b/libodbcpp/odbc-param.cpp index 120703e..a185393 100644 --- a/libodbcpp/odbc-param.cpp +++ b/libodbcpp/odbc-param.cpp @@ -2,25 +2,24 @@ #include "odbc-param.h" #include "odbc-command.h" #include "odbc-error.h" -#include +#include ODBC::Param::Param() : - paramCmd(NULL), + paramCmd(nullptr), paramIdx(0), - paramBound(false) + paramBound(false), + dataLength(0) { } ODBC::Param::Param(Command * c, unsigned int i) : paramCmd(c), paramIdx(i), - paramBound(false) + paramBound(false), + dataLength(0) { } -ODBC::Param::~Param(){ -} - template ParamType * ODBC::Command::makeParam(unsigned int idx) @@ -28,17 +27,14 @@ ODBC::Command::makeParam(unsigned int idx) if (idx >= params.size()) { throw DB::ParameterOutOfRange(); } - Param * & p = params[idx]; + auto & p = params[idx]; if (p) { - ParamType * np = dynamic_cast(p); - if (np) { + if (auto np = dynamic_cast(p.get())) { return np; } - delete p; } - ParamType * np = new ParamType(this, idx); - p = np; - return np; + p = std::make_unique(this, idx); + return static_cast(p.get()); } void @@ -86,7 +82,7 @@ ODBC::Command::bindNull(unsigned int i) makeParam(i)->bind(); } -void +ODBC::StdStringParam & ODBC::StdStringParam::operator=(Glib::ustring const & d) { const char * addr = data.data(); @@ -97,9 +93,10 @@ ODBC::StdStringParam::operator=(Glib::ustring const & d) paramBound = false; bind(); } + return *this; } -void +ODBC::StdStringParam & ODBC::StdStringParam::operator=(std::string_view const & d) { const char * addr = data.data(); @@ -110,9 +107,10 @@ ODBC::StdStringParam::operator=(std::string_view const & d) paramBound = false; bind(); } + return *this; } -void +ODBC::TimeStampParam & ODBC::TimeStampParam::operator=(const boost::posix_time::ptime & d) { data.year = d.date().year(); @@ -122,9 +120,10 @@ ODBC::TimeStampParam::operator=(const boost::posix_time::ptime & d) data.minute = d.time_of_day().minutes(); data.second = d.time_of_day().seconds(); data.fraction = d.time_of_day().fractional_seconds(); + return *this; } -void +ODBC::IntervalParam & ODBC::IntervalParam::operator=(const boost::posix_time::time_duration & d) { data.interval_type = SQL_IS_DAY_TO_SECOND; @@ -134,5 +133,6 @@ ODBC::IntervalParam::operator=(const boost::posix_time::time_duration & d) data.intval.day_second.minute = d.minutes(); data.intval.day_second.second = d.seconds(); data.intval.day_second.fraction = d.fractional_seconds(); + return *this; } diff --git a/libodbcpp/odbc-param.h b/libodbcpp/odbc-param.h index 0981fe9..6ef5ae1 100644 --- a/libodbcpp/odbc-param.h +++ b/libodbcpp/odbc-param.h @@ -4,119 +4,99 @@ #include #include #include -#include "odbc-bind.h" +#include "odbc-param_fwd.h" #include namespace ODBC { - class Command; - class Param : public virtual Bind { - public: - Param(); - Param(Command *, unsigned int idx); - virtual ~Param() = 0; - void bind() const; - - virtual SQLSMALLINT stype() const = 0; // The SQL type ID - virtual SQLINTEGER dp() const = 0; // The decimal place count - virtual const void * dataAddress() const = 0; // The address of the data - - protected: - friend class Column; - mutable Command * paramCmd; - mutable unsigned int paramIdx; - mutable bool paramBound; // Has SqlBind(...) been called since last change of address? - SQLLEN dataLength; - }; - class BooleanParam : public Param { public: BooleanParam() : Param() { } - BooleanParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + BooleanParam(Command * c, unsigned int i) : Param(c, i) { bindLen = BooleanParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_BIT; } virtual SQLSMALLINT stype() const override { return SQL_C_BIT; } virtual SQLULEN size() const override { return sizeof(SQLINTEGER); } virtual SQLINTEGER dp() const override { return 0; } virtual const void * dataAddress() const override { return &data; } - void operator=(const SQLINTEGER & d) { data = d; } + BooleanParam & operator=(const SQLINTEGER & d) { data = d; return *this; } protected: SQLINTEGER data; }; class SignedIntegerParam : public Param { public: SignedIntegerParam() : Param() { } - SignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + SignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { bindLen = SignedIntegerParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_LONG; } virtual SQLSMALLINT stype() const override { return SQL_C_LONG; } virtual SQLULEN size() const override { return sizeof(SQLINTEGER); } virtual SQLINTEGER dp() const override { return 0; } virtual const void * dataAddress() const override { return &data; } - void operator=(const SQLINTEGER & d) { data = d; } + SignedIntegerParam & operator=(const SQLINTEGER & d) { data = d; return *this; } protected: SQLINTEGER data; }; class UnsignedIntegerParam : public Param { public: UnsignedIntegerParam() : Param() { } - UnsignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + UnsignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { bindLen = UnsignedIntegerParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_ULONG; } virtual SQLSMALLINT stype() const override { return SQL_C_ULONG; } virtual SQLULEN size() const override { return sizeof(SQLUINTEGER); } virtual SQLINTEGER dp() const override { return 0; } virtual const void * dataAddress() const override { return &data; } - void operator=(const SQLUINTEGER & d) { data = d; } + UnsignedIntegerParam & operator=(const SQLUINTEGER & d) { data = d; return *this; } protected: SQLUINTEGER data; }; class FloatingPointParam : public Param { public: FloatingPointParam() : Param() { } - FloatingPointParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + FloatingPointParam(Command * c, unsigned int i) : Param(c, i) { bindLen = FloatingPointParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_DOUBLE; } virtual SQLSMALLINT stype() const override { return SQL_C_DOUBLE; } virtual SQLULEN size() const override { return sizeof(SQLDOUBLE); } virtual SQLINTEGER dp() const override { return 10; } virtual const void * dataAddress() const override { return &data; } - void operator=(const SQLDOUBLE & d) { data = d; } + FloatingPointParam & operator=(const SQLDOUBLE & d) { data = d; return *this; } protected: SQLDOUBLE data; }; class StdStringParam : public Param { public: StdStringParam() : Param() { } - StdStringParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + StdStringParam(Command * c, unsigned int i) : Param(c, i) { bindLen = StdStringParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_CHAR; } virtual SQLSMALLINT stype() const override { return SQL_CHAR; } virtual SQLULEN size() const override { return data.length(); } virtual SQLINTEGER dp() const override { return 0; } virtual const void * dataAddress() const override { return data.data(); } - void operator=(const std::string_view & d); - void operator=(const Glib::ustring & d); + StdStringParam & operator=(const std::string_view & d); + StdStringParam & operator=(const Glib::ustring & d); protected: std::string data; }; class IntervalParam : public Param { public: IntervalParam() : Param() { } - IntervalParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + IntervalParam(Command * c, unsigned int i) : Param(c, i) { bindLen = IntervalParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_INTERVAL_DAY_TO_SECOND; } virtual SQLSMALLINT stype() const override { return SQL_INTERVAL_DAY_TO_SECOND; } virtual SQLULEN size() const override { return sizeof(SQL_INTERVAL_STRUCT); } virtual SQLINTEGER dp() const override { return boost::posix_time::time_res_traits::num_fractional_digits(); } virtual const void * dataAddress() const override { return &data; } - void operator=(const boost::posix_time::time_duration & d); + IntervalParam & operator=(const boost::posix_time::time_duration & d); protected: SQL_INTERVAL_STRUCT data; }; class TimeStampParam : public Param { public: TimeStampParam() : Param() { } - TimeStampParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); } + TimeStampParam(Command * c, unsigned int i) : Param(c, i) { bindLen = TimeStampParam::size(); } virtual SQLSMALLINT ctype() const override { return SQL_C_TYPE_TIMESTAMP; } virtual SQLSMALLINT stype() const override { return SQL_TYPE_TIMESTAMP; } virtual SQLULEN size() const override { return sizeof(SQL_TIMESTAMP_STRUCT); } virtual SQLINTEGER dp() const override { return boost::posix_time::time_res_traits::num_fractional_digits(); } virtual const void * dataAddress() const override { return &data; } - void operator=(const boost::posix_time::ptime & d); + TimeStampParam & operator=(const boost::posix_time::ptime & d); protected: SQL_TIMESTAMP_STRUCT data; }; diff --git a/libodbcpp/odbc-param_fwd.h b/libodbcpp/odbc-param_fwd.h new file mode 100644 index 0000000..88c3dae --- /dev/null +++ b/libodbcpp/odbc-param_fwd.h @@ -0,0 +1,29 @@ +#ifndef ODBC_PARAM_FWD_H +#define ODBC_PARAM_FWD_H + +#include +#include "odbc-bind.h" + +namespace ODBC { + class Command; + class Param : public virtual Bind { + public: + Param(); + Param(Command *, unsigned int idx); + void bind() const; + + virtual SQLSMALLINT stype() const = 0; // The SQL type ID + virtual SQLINTEGER dp() const = 0; // The decimal place count + virtual const void * dataAddress() const = 0; // The address of the data + + protected: + friend class Column; + mutable Command * paramCmd; + mutable unsigned int paramIdx; + mutable bool paramBound; // Has SqlBind(...) been called since last change of address? + SQLLEN dataLength; + }; +} + +#endif + diff --git a/libodbcpp/odbc-selectcommand.cpp b/libodbcpp/odbc-selectcommand.cpp index 01da513..ea94fce 100644 --- a/libodbcpp/odbc-selectcommand.cpp +++ b/libodbcpp/odbc-selectcommand.cpp @@ -2,8 +2,7 @@ #include "odbc-error.h" #include "odbc-column.h" #include -#include -#include +#include #include #include @@ -39,7 +38,8 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset) default: { SQLCHAR sqlstatus[6]; - RETCODE diagrc = SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, 1, sqlstatus, NULL, NULL, 0, NULL); + // NOLINTNEXTLINE(hicpp-no-array-decay) + RETCODE diagrc = SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, 1, sqlstatus, nullptr, nullptr, 0, nullptr); if (SQL_SUCCEEDED(diagrc)) { if (!strncmp((const char*)sqlstatus, "01004", 5)) { for (const auto & c : largeColumns) { @@ -47,7 +47,6 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset) } return fetch(SQL_FETCH_RELATIVE, 0); } - fprintf(stderr, "truncation\n"); } } [[ fallthrough ]]; @@ -83,6 +82,7 @@ ODBC::SelectCommand::execute() SQLSMALLINT nameLen, dp, nullable, bindType; SQLULEN bindSize; int sqlcol = col + 1; + // NOLINTNEXTLINE(hicpp-no-array-decay) if (!SQL_SUCCEEDED(rc = SQLDescribeCol(hStmt, sqlcol, _colName, sizeof(_colName), &nameLen, &bindType, &bindSize, &dp, &nullable))) { throw Error(rc, SQL_HANDLE_STMT, hStmt); @@ -129,7 +129,7 @@ ODBC::SelectCommand::execute() throw DB::ColumnTypeNotSupported(); default: SQLLEN octetSize = 0; - if (!SQL_SUCCEEDED(rc = SQLColAttribute(hStmt, sqlcol, SQL_DESC_OCTET_LENGTH, NULL, 0, NULL, &octetSize))) { + if (!SQL_SUCCEEDED(rc = SQLColAttribute(hStmt, sqlcol, SQL_DESC_OCTET_LENGTH, nullptr, 0, nullptr, &octetSize))) { throw Error(rc, SQL_HANDLE_STMT, hStmt); } bindSize = octetSize; diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp index d0373a7..5263eb5 100644 --- a/libodbcpp/unittests/testodbc.cpp +++ b/libodbcpp/unittests/testodbc.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) assertColumnValueHelper(*select, 1, 123.45); assertColumnValueHelper(*select, 2, std::string_view("some text")); // assertColumnValueHelper(*select, 3, true); - assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); + assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, nullptr})); rows += 1; } BOOST_REQUIRE_EQUAL(1, rows); -- cgit v1.2.3