From dbf98a34e08558b91328cb414447e9961c222033 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Sep 2021 14:25:22 +0100 Subject: Add JT recommended warnings --- libodbcpp/Jamfile.jam | 15 +++++ libodbcpp/odbc-column.cpp | 27 ++++---- libodbcpp/odbc-column.h | 138 ++++++++------------------------------- libodbcpp/odbc-command.cpp | 7 +- libodbcpp/odbc-connection.cpp | 24 +++---- libodbcpp/odbc-error.cpp | 2 +- libodbcpp/odbc-modifycommand.cpp | 2 +- libodbcpp/odbc-param.cpp | 55 ++++++++-------- libodbcpp/odbc-param.h | 64 ++++++++++-------- libodbcpp/odbc-param_fwd.h | 2 +- libodbcpp/odbc-selectcommand.cpp | 11 ++-- libodbcpp/unittests/testodbc.cpp | 4 +- 12 files changed, 148 insertions(+), 203 deletions(-) diff --git a/libodbcpp/Jamfile.jam b/libodbcpp/Jamfile.jam index f6078df..83bd5fa 100644 --- a/libodbcpp/Jamfile.jam +++ b/libodbcpp/Jamfile.jam @@ -17,6 +17,21 @@ project release:on debug:extra debug:on + debug:-Wnon-virtual-dtor + debug:-Wold-style-cast + debug:-Wcast-align + debug:-Wunused + debug:-Woverloaded-virtual + debug:-Wpedantic + debug:-Wconversion + debug:-Wsign-conversion + debug:-Wnull-dereference + debug:-Wdouble-promotion + debug:-Wformat=2 + gcc,debug:-Wduplicated-cond + gcc,debug:-Wduplicated-branches + gcc,debug:-Wlogical-op + gcc,debug:-Wuseless-cast coverage:on tidy:hicpp-signed-bitwise ; diff --git a/libodbcpp/odbc-column.cpp b/libodbcpp/odbc-column.cpp index 3d968c2..df22cfb 100644 --- a/libodbcpp/odbc-column.cpp +++ b/libodbcpp/odbc-column.cpp @@ -21,7 +21,7 @@ bool ODBC::CharArrayColumn::resize() { if (bindLen >= SQLLEN(data.size())) { - data.resize(bindLen + 1); + data.resize(static_cast(bindLen + 1)); Column::bind(); if (paramCmd) { paramBound = false; @@ -41,23 +41,13 @@ ODBC::Column::isNull() const void ODBC::Column::bind() { - RETCODE rc = SQLBindCol(selectCmd->hStmt, colNo + 1, ctype(), rwDataAddress(), size(), &bindLen); + RETCODE rc = SQLBindCol(selectCmd->hStmt, static_cast(colNo + 1), ctype(), rwDataAddress(), + static_cast(size()), &bindLen); if (!SQL_SUCCEEDED(rc)) { throw Error(rc, SQL_HANDLE_STMT, selectCmd->hStmt); } } -ODBC::TimeStampColumn::operator boost::posix_time::ptime() const -{ - return boost::posix_time::ptime(boost::gregorian::date(data.year, data.month, data.day), - boost::posix_time::time_duration(data.hour, data.minute, data.second, data.fraction)); -} -ODBC::IntervalColumn::operator boost::posix_time::time_duration() const -{ - auto dur = boost::posix_time::time_duration((24 * data.intval.day_second.day) + data.intval.day_second.hour, - data.intval.day_second.minute, data.intval.day_second.second, data.intval.day_second.fraction); - return (data.interval_sign ? -dur : dur); -} void ODBC::SignedIntegerColumn::apply(DB::HandleField & h) const { @@ -80,7 +70,7 @@ ODBC::CharArrayColumn::apply(DB::HandleField & h) const if (isNull()) { return h.null(); } - h.string({data.data(), (std::size_t)bindLen}); + h.string({data.data(), static_cast(bindLen)}); } void ODBC::TimeStampColumn::apply(DB::HandleField & h) const @@ -88,7 +78,10 @@ ODBC::TimeStampColumn::apply(DB::HandleField & h) const if (isNull()) { return h.null(); } - h.timestamp(*this); + h.timestamp(boost::posix_time::ptime( + boost::gregorian::date(static_cast(data.year), + static_cast(data.month), static_cast(data.day)), + boost::posix_time::time_duration(data.hour, data.minute, data.second, data.fraction))); } void ODBC::IntervalColumn::apply(DB::HandleField & h) const @@ -96,5 +89,7 @@ ODBC::IntervalColumn::apply(DB::HandleField & h) const if (isNull()) { return h.null(); } - h.interval(*this); + auto dur = boost::posix_time::time_duration((24 * data.intval.day_second.day) + data.intval.day_second.hour, + data.intval.day_second.minute, data.intval.day_second.second, data.intval.day_second.fraction); + h.interval(data.interval_sign ? -dur : dur); } diff --git a/libodbcpp/odbc-column.h b/libodbcpp/odbc-column.h index e2783ce..bef5d9d 100644 --- a/libodbcpp/odbc-column.h +++ b/libodbcpp/odbc-column.h @@ -18,58 +18,6 @@ namespace ODBC { virtual void * rwDataAddress() = 0; virtual bool resize(); - virtual operator int() const - { - throw std::bad_cast(); - } - virtual operator long() const - { - throw std::bad_cast(); - } - virtual operator long long() const - { - throw std::bad_cast(); - } - virtual operator unsigned int() const - { - throw std::bad_cast(); - } - virtual operator unsigned long() const - { - throw std::bad_cast(); - } - virtual operator unsigned long long() const - { - throw std::bad_cast(); - } - - virtual operator double() const - { - throw std::bad_cast(); - } - virtual operator float() const - { - throw std::bad_cast(); - } - - virtual operator std::string() const - { - throw std::bad_cast(); - } - virtual operator Glib::ustring() const - { - throw std::bad_cast(); - } - - virtual operator struct tm() const - { - throw std::bad_cast(); - } - virtual operator SQL_TIMESTAMP_STRUCT() const - { - throw std::bad_cast(); - } - [[nodiscard]] bool isNull() const override; virtual void apply(DB::HandleField &) const override = 0; @@ -86,47 +34,39 @@ namespace ODBC { { data.resize(std::max(sizeHint, 64) + 1); } - virtual SQLSMALLINT + SQLSMALLINT ctype() const override { return SQL_C_CHAR; } - virtual SQLSMALLINT + SQLSMALLINT stype() const override { return SQL_CHAR; } - virtual SQLULEN + SQLULEN size() const override { return data.size(); } - virtual SQLINTEGER + SQLSMALLINT dp() const override { return 0; } - virtual const void * + const void * dataAddress() const override { return &data.front(); } - virtual void * + void * rwDataAddress() override { return &data.front(); } void operator=(const Glib::ustring & d); bool resize() override; - virtual operator std::string() const override - { - return std::string(&data.front(), bindLen); - } - virtual operator Glib::ustring() const override - { - return std::string(&data.front(), bindLen); - } - virtual void apply(DB::HandleField &) const override; + void apply(DB::HandleField &) const override; protected: virtual const Param * @@ -142,45 +82,33 @@ namespace ODBC { DB::Column(n, i), Column(sc, n, i) { } - virtual SQLSMALLINT + SQLSMALLINT ctype() const override { return SignedIntegerParam::ctype(); } - virtual SQLULEN + SQLULEN size() const override { return SignedIntegerParam::size(); } - virtual void * + void * rwDataAddress() override { return &data; } - virtual operator int() const override - { - return data; - } - virtual operator long() const override - { - return data; - } - virtual operator long long() const override - { - return data; - } - virtual const Param * + const Param * meAsAParam() const override { return this; } - virtual void apply(DB::HandleField &) const override; + void apply(DB::HandleField &) const override; }; #ifdef COMPLETENESS class UnsignedIntegerColumn : public Column, public UnsignedIntegerParam { public: UnsignedIntegerColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) : Column(sc, n, i) { } - virtual const Param * + const Param * meAsAParam() const override { return this; @@ -193,63 +121,54 @@ namespace ODBC { DB::Column(n, i), Column(sc, n, i) { } - virtual SQLSMALLINT + SQLSMALLINT ctype() const override { return FloatingPointParam::ctype(); } - virtual SQLULEN + SQLULEN size() const override { return FloatingPointParam::size(); } - virtual void * + void * rwDataAddress() override { return &data; } - virtual operator double() const override - { - return data; - } - virtual operator float() const override - { - return data; - } - virtual const Param * + const Param * meAsAParam() const override { return this; } - virtual void apply(DB::HandleField &) const override; + void apply(DB::HandleField &) const override; }; class IntervalColumn : public Column, public IntervalParam { public: IntervalColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) : DB::Column(n, i), Column(sc, n, i) { } - virtual SQLSMALLINT + SQLSMALLINT ctype() const override { return IntervalParam::ctype(); } - virtual SQLULEN + SQLULEN size() const override { return IntervalParam::size(); } - virtual void * + void * rwDataAddress() override { return &data; } - virtual operator boost::posix_time::time_duration() const; - virtual const Param * + const Param * meAsAParam() const override { return this; } - virtual void apply(DB::HandleField &) const override; + void apply(DB::HandleField &) const override; }; class TimeStampColumn : public Column, public TimeStampParam { public: @@ -257,28 +176,27 @@ namespace ODBC { DB::Column(n, i), Column(sc, n, i) { } - virtual SQLSMALLINT + SQLSMALLINT ctype() const override { return TimeStampParam::ctype(); } - virtual SQLULEN + SQLULEN size() const override { return TimeStampParam::size(); } - virtual void * + void * rwDataAddress() override { return &data; } - virtual operator boost::posix_time::ptime() const; - virtual const Param * + const Param * meAsAParam() const override { return this; } - virtual void apply(DB::HandleField &) const override; + void apply(DB::HandleField &) const override; }; } diff --git a/libodbcpp/odbc-command.cpp b/libodbcpp/odbc-command.cpp index c73b3f9..c3e181d 100644 --- a/libodbcpp/odbc-command.cpp +++ b/libodbcpp/odbc-command.cpp @@ -9,11 +9,12 @@ ODBC::Command::Command(const Connection & c, const std::string & s) : DB::Comman if (!SQL_SUCCEEDED(rc)) { throw Error(rc, SQL_HANDLE_STMT, hStmt); } - rc = SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_DYNAMIC, 0); + rc = SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, reinterpret_cast(SQL_CURSOR_DYNAMIC), 0); if (!SQL_SUCCEEDED(rc)) { throw ConnectionError(rc, SQL_HANDLE_STMT, hStmt); } - rc = SQLPrepare(hStmt, (SQLCHAR *)sql.c_str(), sql.length()); + rc = SQLPrepare(hStmt, const_cast(reinterpret_cast(sql.data())), + static_cast(sql.length())); if (!SQL_SUCCEEDED(rc)) { SQLFreeHandle(SQL_HANDLE_STMT, hStmt); throw Error(rc, SQL_HANDLE_STMT, hStmt); @@ -24,5 +25,5 @@ ODBC::Command::Command(const Connection & c, const std::string & s) : DB::Comman SQLFreeHandle(SQL_HANDLE_STMT, hStmt); throw Error(rc, SQL_HANDLE_STMT, hStmt); } - params.resize(pcount); + params.resize(static_cast(pcount)); } diff --git a/libodbcpp/odbc-connection.cpp b/libodbcpp/odbc-connection.cpp index 84e316d..9cb5905 100644 --- a/libodbcpp/odbc-connection.cpp +++ b/libodbcpp/odbc-connection.cpp @@ -7,14 +7,15 @@ #include #include -NAMEDFACTORY("odbc", ODBC::Connection, DB::ConnectionFactory); +NAMEDFACTORY("odbc", ODBC::Connection, DB::ConnectionFactory) ODBC::Connection::Connection(const DSN & d) : env(nullptr), conn(nullptr), thinkDelStyle(DB::BulkDeleteUsingUsing), thinkUpdStyle(DB::BulkUpdateUsingFromSrc) { connectPre(); - RETCODE dberr = SQLConnect(conn, (SQLCHAR *)d.dsn.c_str(), SQL_NTS, (SQLCHAR *)d.username.c_str(), SQL_NTS, - (SQLCHAR *)d.password.c_str(), SQL_NTS); + RETCODE dberr = SQLConnect(conn, const_cast(reinterpret_cast(d.dsn.c_str())), SQL_NTS, + const_cast(reinterpret_cast(d.username.c_str())), SQL_NTS, + const_cast(reinterpret_cast(d.password.c_str())), SQL_NTS); if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_DBC, conn); } @@ -29,7 +30,7 @@ ODBC::Connection::connectPre() throw ConnectionError(dberr, SQL_HANDLE_ENV, env); } - dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0); + dberr = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast(SQL_OV_ODBC3), 0); if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_ENV, env); } @@ -39,7 +40,7 @@ ODBC::Connection::connectPre() throw ConnectionError(dberr, SQL_HANDLE_ENV, env); } - dberr = SQLSetConnectAttr(conn, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0); + dberr = SQLSetConnectAttr(conn, SQL_LOGIN_TIMEOUT, reinterpret_cast(5), 0); if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_ENV, env); } @@ -59,7 +60,7 @@ ODBC::Connection::connectPost() } // Apply known DB specific tweaks // NOLINTNEXTLINE(hicpp-no-array-decay) - if (strcasestr((const char *)info.data(), "myodbc")) { + if (strcasestr(reinterpret_cast(info.data()), "myodbc")) { thinkDelStyle = DB::BulkDeleteUsingUsingAlias; thinkUpdStyle = DB::BulkUpdateUsingJoin; } @@ -69,8 +70,8 @@ ODBC::Connection::Connection(const std::string & s) : env(nullptr), conn(nullptr), thinkDelStyle(DB::BulkDeleteUsingUsing), thinkUpdStyle(DB::BulkUpdateUsingFromSrc) { connectPre(); - RETCODE dberr = SQLDriverConnect( - conn, nullptr, (SQLCHAR *)s.c_str(), s.length(), nullptr, 0, nullptr, SQL_DRIVER_NOPROMPT); + RETCODE dberr = SQLDriverConnect(conn, nullptr, const_cast(reinterpret_cast(s.c_str())), + static_cast(s.length()), nullptr, 0, nullptr, SQL_DRIVER_NOPROMPT); if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_DBC, conn); } @@ -153,11 +154,12 @@ ODBC::Connection::getAttrStr(SQLINTEGER attr) const std::string rtn; rtn.resize(BUFSIZ); SQLINTEGER size = 0; - SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, (unsigned char *)rtn.c_str(), BUFSIZ, &size); + SQLRETURN dberr = SQLGetConnectAttr( + conn, attr, const_cast(reinterpret_cast(rtn.c_str())), BUFSIZ, &size); if (!SQL_SUCCEEDED(dberr)) { throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn); } - rtn.resize(size); + rtn.resize(static_cast(size)); return rtn; } @@ -165,7 +167,7 @@ SQLINTEGER ODBC::Connection::getAttrInt(SQLINTEGER attr) const { SQLINTEGER result; - SQLINTEGER dberr = SQLGetConnectAttr(conn, attr, &result, sizeof(result), nullptr); + SQLRETURN 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-error.cpp b/libodbcpp/odbc-error.cpp index 93f11c0..0f998d5 100644 --- a/libodbcpp/odbc-error.cpp +++ b/libodbcpp/odbc-error.cpp @@ -9,7 +9,7 @@ namespace AdHoc { write(stream & s, const std::array & sqlstatus, const Pn &... pn) { static_assert(l > 5); - s.write((const char * const)sqlstatus.data(), 5); + s.write(reinterpret_cast(sqlstatus.data()), 5); StreamWriter::next(s, pn...); } }; diff --git a/libodbcpp/odbc-modifycommand.cpp b/libodbcpp/odbc-modifycommand.cpp index 2fca416..a5f5918 100644 --- a/libodbcpp/odbc-modifycommand.cpp +++ b/libodbcpp/odbc-modifycommand.cpp @@ -21,7 +21,7 @@ ODBC::ModifyCommand::execute(bool anc) throw Error(rc, SQL_HANDLE_STMT, hStmt); } if (rows > 0 || anc) { - return rows; + return static_cast(rows); } throw DB::NoRowsAffected(); } diff --git a/libodbcpp/odbc-param.cpp b/libodbcpp/odbc-param.cpp index cdaf97c..20a02bb 100644 --- a/libodbcpp/odbc-param.cpp +++ b/libodbcpp/odbc-param.cpp @@ -29,8 +29,9 @@ void ODBC::Param::bind() const { if (!paramBound) { - RETCODE rc = SQLBindParameter(paramCmd->hStmt, paramIdx + 1, SQL_PARAM_INPUT, ctype(), stype(), size(), dp(), - const_cast(dataAddress()), size(), &bindLen); + SQLRETURN rc = SQLBindParameter(paramCmd->hStmt, static_cast(paramIdx + 1), SQL_PARAM_INPUT, + ctype(), stype(), size(), dp(), const_cast(dataAddress()), static_cast(size()), + &bindLen); if (!SQL_SUCCEEDED(rc)) { throw Error(rc, SQL_HANDLE_STMT, paramCmd->hStmt); } @@ -45,23 +46,23 @@ ODBC::Param::bind() const *p = val; \ p->bind(); \ } -SIMPLEBINDER(int, SignedIntegerParam, I); -SIMPLEBINDER(long, SignedIntegerParam, I); -SIMPLEBINDER(long long, SignedIntegerParam, I); -SIMPLEBINDER(unsigned int, UnsignedIntegerParam, I); -SIMPLEBINDER(unsigned long int, UnsignedIntegerParam, I); -SIMPLEBINDER(unsigned long long int, UnsignedIntegerParam, I); +SIMPLEBINDER(int, SignedIntegerParam, I) +SIMPLEBINDER(long, SignedIntegerParam, I) +SIMPLEBINDER(long long, SignedIntegerParam, I) +SIMPLEBINDER(unsigned int, UnsignedIntegerParam, I) +SIMPLEBINDER(unsigned long int, UnsignedIntegerParam, I) +SIMPLEBINDER(unsigned long long int, UnsignedIntegerParam, I) -SIMPLEBINDER(bool, BooleanParam, B); +SIMPLEBINDER(bool, BooleanParam, B) -SIMPLEBINDER(double, FloatingPointParam, F); -SIMPLEBINDER(float, FloatingPointParam, F); +SIMPLEBINDER(double, FloatingPointParam, F) +SIMPLEBINDER(float, FloatingPointParam, F) -SIMPLEBINDER(const Glib::ustring &, StdStringParam, S); -SIMPLEBINDER(const std::string_view &, StdStringParam, S); +SIMPLEBINDER(const Glib::ustring &, StdStringParam, S) +SIMPLEBINDER(const std::string_view &, StdStringParam, S) -SIMPLEBINDER(const boost::posix_time::ptime &, TimeStampParam, T); -SIMPLEBINDER(const boost::posix_time::time_duration &, IntervalParam, T); +SIMPLEBINDER(const boost::posix_time::ptime &, TimeStampParam, T) +SIMPLEBINDER(const boost::posix_time::time_duration &, IntervalParam, T) void ODBC::Command::bindNull(unsigned int i) @@ -74,7 +75,7 @@ ODBC::StdStringParam::operator=(Glib::ustring const & d) { const char * addr = data.data(); data = d; - bindLen = d.bytes(); + bindLen = static_cast(d.bytes()); // cppcheck-suppress invalidContainer if (addr != data.data()) { paramBound = false; @@ -88,7 +89,7 @@ ODBC::StdStringParam::operator=(std::string_view const & d) { const char * addr = data.data(); data = d; - bindLen = d.length(); + bindLen = static_cast(d.length()); // cppcheck-suppress invalidContainer if (addr != data.data()) { paramBound = false; @@ -100,13 +101,13 @@ ODBC::StdStringParam::operator=(std::string_view const & d) ODBC::TimeStampParam & ODBC::TimeStampParam::operator=(const boost::posix_time::ptime & d) { - data.year = d.date().year(); + data.year = static_cast(d.date().year()); data.month = d.date().month(); data.day = d.date().day(); - data.hour = d.time_of_day().hours(); - data.minute = d.time_of_day().minutes(); - data.second = d.time_of_day().seconds(); - data.fraction = d.time_of_day().fractional_seconds(); + data.hour = static_cast(d.time_of_day().hours()); + data.minute = static_cast(d.time_of_day().minutes()); + data.second = static_cast(d.time_of_day().seconds()); + data.fraction = static_cast(d.time_of_day().fractional_seconds()); return *this; } @@ -115,10 +116,10 @@ ODBC::IntervalParam::operator=(const boost::posix_time::time_duration & d) { data.interval_type = SQL_IS_DAY_TO_SECOND; data.interval_sign = d.is_negative(); - data.intval.day_second.day = d.hours() / 24; - data.intval.day_second.hour = d.hours() % 24; - data.intval.day_second.minute = d.minutes(); - data.intval.day_second.second = d.seconds(); - data.intval.day_second.fraction = d.fractional_seconds(); + data.intval.day_second.day = static_cast(d.hours() / 24); + data.intval.day_second.hour = static_cast(d.hours() % 24); + data.intval.day_second.minute = static_cast(d.minutes()); + data.intval.day_second.second = static_cast(d.seconds()); + data.intval.day_second.fraction = static_cast(d.fractional_seconds()); return *this; } diff --git a/libodbcpp/odbc-param.h b/libodbcpp/odbc-param.h index 03aaef5..58ed9d2 100644 --- a/libodbcpp/odbc-param.h +++ b/libodbcpp/odbc-param.h @@ -3,7 +3,14 @@ #include "odbc-param_fwd.h" #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wsign-conversion" +#ifndef __clang__ +# pragma GCC diagnostic ignored "-Wuseless-cast" +#endif #include +#pragma GCC diagnostic pop #include #include @@ -13,7 +20,7 @@ namespace ODBC { BooleanParam() : Param() { } BooleanParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = BooleanParam::size(); + bindLen = static_cast(BooleanParam::size()); } virtual SQLSMALLINT ctype() const override @@ -30,7 +37,7 @@ namespace ODBC { { return sizeof(SQLINTEGER); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return 0; @@ -55,24 +62,24 @@ namespace ODBC { SignedIntegerParam() : Param() { } SignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = SignedIntegerParam::size(); + bindLen = static_cast(SignedIntegerParam::size()); } virtual SQLSMALLINT ctype() const override { - return SQL_C_LONG; + return SQL_C_SBIGINT; } virtual SQLSMALLINT stype() const override { - return SQL_C_LONG; + return SQL_C_SBIGINT; } virtual SQLULEN size() const override { - return sizeof(SQLINTEGER); + return sizeof(data); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return 0; @@ -83,38 +90,38 @@ namespace ODBC { return &data; } SignedIntegerParam & - operator=(const SQLINTEGER & d) + operator=(const SQLBIGINT & d) { data = d; return *this; } protected: - SQLINTEGER data; + SQLBIGINT data; }; class UnsignedIntegerParam : public Param { public: UnsignedIntegerParam() : Param() { } UnsignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = UnsignedIntegerParam::size(); + bindLen = static_cast(UnsignedIntegerParam::size()); } virtual SQLSMALLINT ctype() const override { - return SQL_C_ULONG; + return SQL_C_UBIGINT; } virtual SQLSMALLINT stype() const override { - return SQL_C_ULONG; + return SQL_C_UBIGINT; } virtual SQLULEN size() const override { - return sizeof(SQLUINTEGER); + return sizeof(data); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return 0; @@ -125,21 +132,21 @@ namespace ODBC { return &data; } UnsignedIntegerParam & - operator=(const SQLUINTEGER & d) + operator=(const SQLUBIGINT & d) { data = d; return *this; } protected: - SQLUINTEGER data; + SQLUBIGINT data; }; class FloatingPointParam : public Param { public: FloatingPointParam() : Param() { } FloatingPointParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = FloatingPointParam::size(); + bindLen = static_cast(FloatingPointParam::size()); } virtual SQLSMALLINT ctype() const override @@ -156,7 +163,7 @@ namespace ODBC { { return sizeof(SQLDOUBLE); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return 10; @@ -167,11 +174,16 @@ namespace ODBC { return &data; } FloatingPointParam & - operator=(const SQLDOUBLE & d) + operator=(const double & d) { data = d; return *this; } + FloatingPointParam & + operator=(const float & f) + { + return operator=(static_cast(f)); + } protected: SQLDOUBLE data; @@ -181,7 +193,7 @@ namespace ODBC { StdStringParam() : Param() { } StdStringParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = StdStringParam::size(); + bindLen = static_cast(StdStringParam::size()); } virtual SQLSMALLINT ctype() const override @@ -198,7 +210,7 @@ namespace ODBC { { return data.length(); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return 0; @@ -219,7 +231,7 @@ namespace ODBC { IntervalParam() : Param() { } IntervalParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = IntervalParam::size(); + bindLen = static_cast(IntervalParam::size()); } virtual SQLSMALLINT ctype() const override @@ -236,7 +248,7 @@ namespace ODBC { { return sizeof(SQL_INTERVAL_STRUCT); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return boost::posix_time::time_res_traits::num_fractional_digits(); @@ -256,7 +268,7 @@ namespace ODBC { TimeStampParam() : Param() { } TimeStampParam(Command * c, unsigned int i) : Param(c, i) { - bindLen = TimeStampParam::size(); + bindLen = static_cast(TimeStampParam::size()); } virtual SQLSMALLINT ctype() const override @@ -273,7 +285,7 @@ namespace ODBC { { return sizeof(SQL_TIMESTAMP_STRUCT); } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return boost::posix_time::time_res_traits::num_fractional_digits(); @@ -310,7 +322,7 @@ namespace ODBC { { return 0; } - virtual SQLINTEGER + virtual SQLSMALLINT dp() const override { return 0; diff --git a/libodbcpp/odbc-param_fwd.h b/libodbcpp/odbc-param_fwd.h index 6c32d02..5406bf5 100644 --- a/libodbcpp/odbc-param_fwd.h +++ b/libodbcpp/odbc-param_fwd.h @@ -13,7 +13,7 @@ namespace ODBC { void bind() const; virtual SQLSMALLINT stype() const = 0; // The SQL type ID - virtual SQLINTEGER dp() const = 0; // The decimal place count + virtual SQLSMALLINT dp() const = 0; // The decimal place count virtual const void * dataAddress() const = 0; // The address of the data protected: diff --git a/libodbcpp/odbc-selectcommand.cpp b/libodbcpp/odbc-selectcommand.cpp index 9d8a344..191bb1e 100644 --- a/libodbcpp/odbc-selectcommand.cpp +++ b/libodbcpp/odbc-selectcommand.cpp @@ -56,7 +56,7 @@ ODBC::SelectCommand::fetch() void ODBC::SelectCommand::execute() { - RETCODE rc = SQLExecute(hStmt); + SQLRETURN rc = SQLExecute(hStmt); if (!SQL_SUCCEEDED(rc)) { throw Error(rc, SQL_HANDLE_STMT, hStmt); } @@ -64,17 +64,18 @@ ODBC::SelectCommand::execute() if (!SQL_SUCCEEDED(rc = SQLNumResultCols(hStmt, &colCount))) { throw Error(rc, SQL_HANDLE_STMT, hStmt); } - for (int col = 0; col < colCount; col++) { + for (SQLUSMALLINT col = 0; col < colCount; col++) { std::array _colName {}; SQLSMALLINT nameLen, dp, nullable, bindType; SQLULEN bindSize; - int sqlcol = col + 1; + SQLUSMALLINT sqlcol = col + 1; // NOLINTNEXTLINE(hicpp-no-array-decay) if (!SQL_SUCCEEDED(rc = SQLDescribeCol(hStmt, sqlcol, _colName.data(), _colName.size(), &nameLen, &bindType, &bindSize, &dp, &nullable))) { throw Error(rc, SQL_HANDLE_STMT, hStmt); } - Glib::ustring colName((const char *)_colName.data(), nameLen); + Glib::ustring colName( + reinterpret_cast(_colName.data()), static_cast(nameLen)); DB::Column * ncol; switch (bindType) { case SQL_DECIMAL: @@ -120,7 +121,7 @@ ODBC::SelectCommand::execute() = SQLColAttribute(hStmt, sqlcol, SQL_DESC_OCTET_LENGTH, nullptr, 0, nullptr, &octetSize))) { throw Error(rc, SQL_HANDLE_STMT, hStmt); } - bindSize = octetSize; + bindSize = static_cast(octetSize); auto lc = std::make_unique(this, colName, col, bindSize); largeColumns.insert(lc.get()); ncol = insertColumn(std::move(lc)).get(); diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp index 14fe0a3..1b3c42a 100644 --- a/libodbcpp/unittests/testodbc.cpp +++ b/libodbcpp/unittests/testodbc.cpp @@ -22,7 +22,7 @@ public: BOOST_GLOBAL_FIXTURE(StandardMockDatabase); -BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore); +BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore) BOOST_AUTO_TEST_CASE(transactions) { @@ -106,4 +106,4 @@ BOOST_AUTO_TEST_CASE(multibyte) BOOST_REQUIRE_EQUAL(250, rows); } -BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3