From 332e099b19bd04db46cfffdf7d06b8a888169d49 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Mar 2019 11:43:22 +0000 Subject: Tidy fixes for latest clang --- libodbcpp/odbc-column.h | 2 +- libodbcpp/odbc-connection.cpp | 6 +++--- libodbcpp/odbc-error.cpp | 17 +++++++++-------- libodbcpp/odbc-selectcommand.cpp | 14 +++++++------- 4 files changed, 20 insertions(+), 19 deletions(-) (limited to 'libodbcpp') 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 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 +#include namespace AdHoc { StreamWriterT('5') { - template - static void write(stream & s, const SQLCHAR sqlstatus[6], const Pn & ... pn) + template + static void write(stream & s, const std::array & sqlstatus, const Pn & ... pn) { - s.write(reinterpret_cast(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 sqlstatus {}; SQLINTEGER sqlerr; - SQLCHAR sqlerrmsg[12800]; + std::array 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 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 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 _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: -- cgit v1.2.3