summaryrefslogtreecommitdiff
path: root/libodbcpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-03-30 11:43:22 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2019-03-30 11:43:22 +0000
commit332e099b19bd04db46cfffdf7d06b8a888169d49 (patch)
tree2dd2e401ce3f228d311cb3d0867465c28bb29045 /libodbcpp
parentBring inline with clang-tidy checks (diff)
downloadlibdbpp-odbc-332e099b19bd04db46cfffdf7d06b8a888169d49.tar.bz2
libdbpp-odbc-332e099b19bd04db46cfffdf7d06b8a888169d49.tar.xz
libdbpp-odbc-332e099b19bd04db46cfffdf7d06b8a888169d49.zip
Tidy fixes for latest clanglibdbpp-odbc-1.4.1
Diffstat (limited to 'libodbcpp')
-rw-r--r--libodbcpp/odbc-column.h2
-rw-r--r--libodbcpp/odbc-connection.cpp6
-rw-r--r--libodbcpp/odbc-error.cpp17
-rw-r--r--libodbcpp/odbc-selectcommand.cpp14
4 files changed, 20 insertions, 19 deletions
diff --git a/libodbcpp/odbc-column.h b/libodbcpp/odbc-column.h
index 85f1b97..5d7c7d4 100644
--- a/libodbcpp/odbc-column.h
+++ b/libodbcpp/odbc-column.h
@@ -34,7 +34,7 @@ namespace ODBC {
virtual operator struct tm () const { throw std::bad_cast(); }
virtual operator SQL_TIMESTAMP_STRUCT () const { throw std::bad_cast(); }
- bool isNull() const override;
+ [[nodiscard]] bool isNull() const override;
virtual void apply(DB::HandleField &) const override = 0;
const SelectCommand * selectCmd;
diff --git a/libodbcpp/odbc-connection.cpp b/libodbcpp/odbc-connection.cpp
index 4e4a0a1..8ecaf2c 100644
--- a/libodbcpp/odbc-connection.cpp
+++ b/libodbcpp/odbc-connection.cpp
@@ -55,14 +55,14 @@ ODBC::Connection::connectPost()
if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_DBC, conn);
}
- char info[1024];
- dberr = SQLGetInfo(conn, SQL_DRIVER_NAME, (SQLCHAR*)info, sizeof(info), nullptr);
+ std::array<SQLCHAR, 1024> info {};
+ dberr = SQLGetInfo(conn, SQL_DRIVER_NAME, info.data(), info.size(), nullptr);
if (!SQL_SUCCEEDED(dberr)) {
throw ConnectionError(dberr, SQL_HANDLE_DBC, conn);
}
// Apply known DB specific tweaks
// NOLINTNEXTLINE(hicpp-no-array-decay)
- if (strstr(info, "myodbc")) {
+ if (strcasestr((const char *)info.data(), "myodbc")) {
thinkDelStyle = DB::BulkDeleteUsingUsingAlias;
thinkUpdStyle = DB::BulkUpdateUsingJoin;
}
diff --git a/libodbcpp/odbc-error.cpp b/libodbcpp/odbc-error.cpp
index 7179a17..afa1d42 100644
--- a/libodbcpp/odbc-error.cpp
+++ b/libodbcpp/odbc-error.cpp
@@ -1,12 +1,14 @@
#include "odbc-error.h"
#include <compileTimeFormatter.h>
+#include <array>
namespace AdHoc {
StreamWriterT('5') {
- template<typename ... Pn>
- static void write(stream & s, const SQLCHAR sqlstatus[6], const Pn & ... pn)
+ template<std::size_t l, typename ... Pn>
+ static void write(stream & s, const std::array<SQLCHAR, l> & sqlstatus, const Pn & ... pn)
{
- s.write(reinterpret_cast<const char *>(sqlstatus), 5);
+ static_assert(l > 5);
+ s.write((const char * const)sqlstatus.data(), 5);
StreamWriter::next(s, pn...);
}
};
@@ -18,16 +20,15 @@ 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];
+ std::array<SQLCHAR, 6> sqlstatus {};
SQLINTEGER sqlerr;
- SQLCHAR sqlerrmsg[12800];
+ std::array<SQLCHAR, 12800> sqlerrmsg {};
- // NOLINTNEXTLINE(hicpp-no-array-decay)
- SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus, &sqlerr, sqlerrmsg, sizeof(sqlerrmsg), nullptr);
+ SQLRETURN rc = SQLGetDiagRec(handletype, handle, 1, sqlstatus.data(), &sqlerr, sqlerrmsg.data(), sqlerrmsg.size(), nullptr);
switch (rc) {
case SQL_SUCCESS:
case SQL_SUCCESS_WITH_INFO:
- msg = ODBCErrorWithInfo::get(err, sqlerr, sqlstatus, sqlerrmsg);
+ msg = ODBCErrorWithInfo::get(err, sqlerr, sqlstatus, sqlerrmsg.data());
break;
case SQL_INVALID_HANDLE:
diff --git a/libodbcpp/odbc-selectcommand.cpp b/libodbcpp/odbc-selectcommand.cpp
index ea94fce..82947a7 100644
--- a/libodbcpp/odbc-selectcommand.cpp
+++ b/libodbcpp/odbc-selectcommand.cpp
@@ -26,6 +26,7 @@ ODBC::SelectCommand::fetch()
return fetch(SQL_FETCH_NEXT, 0);
}
+constexpr std::array<SQLCHAR, 6> truncated = { '0', '1', '0', '0', '4', '\0' };
bool
ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
{
@@ -37,11 +38,10 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
case SQL_SUCCESS_WITH_INFO:
default:
{
- SQLCHAR sqlstatus[6];
- // NOLINTNEXTLINE(hicpp-no-array-decay)
- RETCODE diagrc = SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, 1, sqlstatus, nullptr, nullptr, 0, nullptr);
+ std::array<SQLCHAR, 6> sqlstatus {};
+ RETCODE diagrc = SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, 1, sqlstatus.data(), nullptr, nullptr, 0, nullptr);
if (SQL_SUCCEEDED(diagrc)) {
- if (!strncmp((const char*)sqlstatus, "01004", 5)) {
+ if (sqlstatus == truncated) {
for (const auto & c : largeColumns) {
c->resize();
}
@@ -78,16 +78,16 @@ ODBC::SelectCommand::execute()
throw Error(rc, SQL_HANDLE_STMT, hStmt);
}
for (int col = 0; col < colCount; col++) {
- SQLCHAR _colName[300];
+ std::array<SQLCHAR, 300> _colName {};
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,
+ 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, nameLen);
+ Glib::ustring colName((const char *)_colName.data(), nameLen);
DB::Column * ncol;
switch (bindType) {
case SQL_DECIMAL: