summaryrefslogtreecommitdiff
path: root/libodbcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libodbcpp')
-rw-r--r--libodbcpp/Jamfile.jam15
-rw-r--r--libodbcpp/odbc-column.cpp27
-rw-r--r--libodbcpp/odbc-column.h138
-rw-r--r--libodbcpp/odbc-command.cpp7
-rw-r--r--libodbcpp/odbc-connection.cpp24
-rw-r--r--libodbcpp/odbc-error.cpp2
-rw-r--r--libodbcpp/odbc-modifycommand.cpp2
-rw-r--r--libodbcpp/odbc-param.cpp55
-rw-r--r--libodbcpp/odbc-param.h64
-rw-r--r--libodbcpp/odbc-param_fwd.h2
-rw-r--r--libodbcpp/odbc-selectcommand.cpp11
-rw-r--r--libodbcpp/unittests/testodbc.cpp4
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
<variant>release:<lto>on
<variant>debug:<warnings>extra
<variant>debug:<warnings-as-errors>on
+ <variant>debug:<cflags>-Wnon-virtual-dtor
+ <variant>debug:<cflags>-Wold-style-cast
+ <variant>debug:<cflags>-Wcast-align
+ <variant>debug:<cflags>-Wunused
+ <variant>debug:<cflags>-Woverloaded-virtual
+ <variant>debug:<cflags>-Wpedantic
+ <variant>debug:<cflags>-Wconversion
+ <variant>debug:<cflags>-Wsign-conversion
+ <variant>debug:<cflags>-Wnull-dereference
+ <variant>debug:<cflags>-Wdouble-promotion
+ <variant>debug:<cflags>-Wformat=2
+ <toolset>gcc,<variant>debug:<cflags>-Wduplicated-cond
+ <toolset>gcc,<variant>debug:<cflags>-Wduplicated-branches
+ <toolset>gcc,<variant>debug:<cflags>-Wlogical-op
+ <toolset>gcc,<variant>debug:<cflags>-Wuseless-cast
<variant>coverage:<coverage>on
<toolset>tidy:<xcheckxx>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<std::size_t>(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<SQLUSMALLINT>(colNo + 1), ctype(), rwDataAddress(),
+ static_cast<SQLLEN>(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<std::size_t>(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<unsigned short int>(data.year),
+ static_cast<unsigned short int>(data.month), static_cast<unsigned short int>(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<SQLULEN>(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<SQLPOINTER>(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<SQLCHAR *>(reinterpret_cast<const SQLCHAR *>(sql.data())),
+ static_cast<int>(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<std::string::size_type>(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 <sqlext.h>
#include <stdexcept>
-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<SQLCHAR *>(reinterpret_cast<const SQLCHAR *>(d.dsn.c_str())), SQL_NTS,
+ const_cast<SQLCHAR *>(reinterpret_cast<const SQLCHAR *>(d.username.c_str())), SQL_NTS,
+ const_cast<SQLCHAR *>(reinterpret_cast<const SQLCHAR *>(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<SQLPOINTER *>(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<SQLPOINTER *>(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<const char *>(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<SQLCHAR *>(reinterpret_cast<const SQLCHAR *>(s.c_str())),
+ static_cast<SQLSMALLINT>(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<SQLCHAR *>(reinterpret_cast<const SQLCHAR *>(rtn.c_str())), BUFSIZ, &size);
if (!SQL_SUCCEEDED(dberr)) {
throw ODBC::Error(dberr, SQL_HANDLE_DBC, conn);
}
- rtn.resize(size);
+ rtn.resize(static_cast<std::string::size_type>(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<SQLCHAR, l> & sqlstatus, const Pn &... pn)
{
static_assert(l > 5);
- s.write((const char * const)sqlstatus.data(), 5);
+ s.write(reinterpret_cast<const char * const>(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<unsigned int>(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<void *>(dataAddress()), size(), &bindLen);
+ SQLRETURN rc = SQLBindParameter(paramCmd->hStmt, static_cast<SQLUSMALLINT>(paramIdx + 1), SQL_PARAM_INPUT,
+ ctype(), stype(), size(), dp(), const_cast<void *>(dataAddress()), static_cast<SQLLEN>(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<SQLLEN>(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<SQLLEN>(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<SQLSMALLINT>(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<SQLUSMALLINT>(d.time_of_day().hours());
+ data.minute = static_cast<SQLUSMALLINT>(d.time_of_day().minutes());
+ data.second = static_cast<SQLUSMALLINT>(d.time_of_day().seconds());
+ data.fraction = static_cast<SQLUSMALLINT>(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<SQLUSMALLINT>(d.hours() / 24);
+ data.intval.day_second.hour = static_cast<SQLUSMALLINT>(d.hours() % 24);
+ data.intval.day_second.minute = static_cast<SQLUSMALLINT>(d.minutes());
+ data.intval.day_second.second = static_cast<SQLUSMALLINT>(d.seconds());
+ data.intval.day_second.fraction = static_cast<SQLUSMALLINT>(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 <boost/date_time/posix_time/posix_time_types.hpp>
+#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 <glibmm/ustring.h>
+#pragma GCC diagnostic pop
#include <malloc.h>
#include <sqlext.h>
@@ -13,7 +20,7 @@ namespace ODBC {
BooleanParam() : Param() { }
BooleanParam(Command * c, unsigned int i) : Param(c, i)
{
- bindLen = BooleanParam::size();
+ bindLen = static_cast<SQLLEN>(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<SQLLEN>(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<SQLLEN>(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<SQLLEN>(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<double>(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<SQLLEN>(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<SQLLEN>(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<SQLLEN>(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<SQLCHAR, 300> _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<const char *>(_colName.data()), static_cast<Glib::ustring::size_type>(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<decltype(bindSize)>(octetSize);
auto lc = std::make_unique<CharArrayColumn>(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()