Skip to content

Commit 76d0839

Browse files
committed
Updated PJ Naughter's ODBCWrappers library to the latest version available.
1 parent e249c00 commit 76d0839

File tree

4 files changed

+85
-28
lines changed

4 files changed

+85
-28
lines changed

ODBCWrappers.h

+84-27
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ History: PJN / 24-09-2011 1. Initial creation
8585
PJN / 12-05-2023 1. Updated copyright details
8686
2. Updated modules to indicate that it needs to be compiled using /std:c++17. Thanks to Martin Richter
8787
for reporting this issue.
88+
PJN / 15-12-2023 1. Updated module to remove usage of _if_exists by now using ODBCVER and _ATL_MODULES
89+
preprocessor macro checks along with SFINAE.
8890
8991
Copyright (c) 2011 - 2023 by PJ Naughter (Web: www.naughter.com, Email: [email protected])
9092
@@ -107,7 +109,7 @@ to maintain a single distribution point for the source code.
107109

108110
#if _MSVC_LANG < 201703
109111
#error ODBCWrappers requires a minimum C++ language standard of /std:c++17
110-
#endif //#if __cplusplus < 201703
112+
#endif //#if _MSVC_LANG < 201703
111113

112114
#ifndef __ODBCWRAPPERS_H__
113115
#define __ODBCWRAPPERS_H__
@@ -539,7 +541,7 @@ namespace CODBC
539541
}
540542
}
541543

542-
_NODISCARD operator SQLHANDLE() const noexcept
544+
[[nodiscard]] operator SQLHANDLE() const noexcept
543545
{
544546
return m_h;
545547
}
@@ -581,7 +583,7 @@ namespace CODBC
581583
return SQLGetDiagRec(m_Type, m_h, iRecord, szSqlState, pfNativeError, szErrorMsg, cchErrorMsgMax, pcchErrorMsg);
582584
}
583585

584-
void GetDiagRecords(_Out_ std::vector<String>& records)
586+
void GetDiagRecords(_Out_ std::vector<String>& records) const
585587
{
586588
//clear the vector
587589
records.clear();
@@ -609,29 +611,27 @@ namespace CODBC
609611
}
610612
}
611613

612-
__if_exists(SQLCompleteAsync)
614+
#if (ODBCVER >= 0x0380)
615+
SQLRETURN CancelHandle() noexcept
613616
{
614-
SQLRETURN CancelHandle() noexcept
615-
{
616-
//Validate our parameters
617+
//Validate our parameters
617618
#pragma warning(suppress: 26477)
618-
ATLASSERT(m_h != SQL_NULL_HANDLE);
619+
ATLASSERT(m_h != SQL_NULL_HANDLE);
619620

620-
return SQLCancelHandle(m_Type, m_h);
621-
}
622-
} //__if_exists(SQLCompleteAsync)
621+
return SQLCancelHandle(m_Type, m_h);
622+
}
623+
#endif //#if (ODBCVER >= 0x0380)
623624

624-
__if_exists(SQLCompleteAsync)
625+
#if (ODBCVER >= 0x0380)
626+
SQLRETURN CompleteAsync(_Out_ RETCODE* AsyncRetCodePtr) noexcept
625627
{
626-
SQLRETURN CompleteAsync(_Out_ RETCODE* AsyncRetCodePtr) noexcept
627-
{
628-
//Validate our parameters
628+
//Validate our parameters
629629
#pragma warning(suppress: 26477)
630-
ATLASSERT(m_h != SQL_NULL_HANDLE);
630+
ATLASSERT(m_h != SQL_NULL_HANDLE);
631631

632-
return SQLCompleteAsync(m_Type, m_h, AsyncRetCodePtr);
633-
}
634-
} //__if_exists(SQLCompleteAsync)
632+
return SQLCompleteAsync(m_Type, m_h, AsyncRetCodePtr);
633+
}
634+
#endif //#if (ODBCVER >= 0x0380)
635635

636636
#pragma warning(suppress: 26440)
637637
void ValidateReturnValue(_In_ SQLRETURN nRet) const
@@ -1883,7 +1883,56 @@ namespace CODBC
18831883
};
18841884

18851885

1886-
//The base class which accessor classes derive from. T is the class that contains the data that will be accessed
1886+
#ifdef _ATL_MODULES
1887+
1888+
template<typename, typename T>
1889+
struct _Has_GetBindParametersEntries
1890+
{
1891+
static_assert(std::integral_constant<T, false>::value, "Second template parameter needs to be of function type.");
1892+
};
1893+
1894+
template<typename C, typename Ret, typename... Args>
1895+
struct _Has_GetBindParametersEntries<C, Ret(Args...)>
1896+
{
1897+
private:
1898+
template<typename T>
1899+
static constexpr auto check(T*) -> typename std::is_same<decltype(std::declval<T>()._GetBindParametersEntries(std::declval<Args>()...)), Ret>::type;
1900+
1901+
template<typename>
1902+
static constexpr std::false_type check(...);
1903+
1904+
using type = decltype(check<C>(nullptr));
1905+
1906+
public:
1907+
static constexpr bool value = type::value;
1908+
};
1909+
1910+
template<typename, typename T>
1911+
struct _Has_GetBindColumnEntries
1912+
{
1913+
static_assert(std::integral_constant<T, false>::value, "Second template parameter needs to be of function type.");
1914+
};
1915+
1916+
template<typename C, typename Ret, typename... Args>
1917+
struct _Has_GetBindColumnEntries<C, Ret(Args...)>
1918+
{
1919+
private:
1920+
template<typename T>
1921+
static constexpr auto check(T*) -> typename std::is_same<decltype(std::declval<T>()._GetBindColumnEntries(std::declval<Args>()...)), Ret>::type;
1922+
1923+
template<typename>
1924+
static constexpr std::false_type check(...);
1925+
1926+
using type = decltype(check<C>(nullptr));
1927+
1928+
public:
1929+
static constexpr bool value = type::value;
1930+
};
1931+
1932+
#endif //#ifdef _ATL_MODULES
1933+
1934+
1935+
//The base class which accessor classes derive from. T is the class that contains the data that will be accessed.
18871936
template<class T>
18881937
class CAccessor : public T
18891938
{
@@ -1898,7 +1947,11 @@ namespace CODBC
18981947
#pragma warning(suppress: 26496)
18991948
SQLRETURN nRet{ SQL_SUCCESS };
19001949

1950+
#ifdef _ATL_MODULES
1951+
if constexpr (_Has_GetBindColumnEntries<T, SQLRETURN(const CODBC::CStatement*, int*, std::vector<SQLLEN>*)>::value)
1952+
#else
19011953
__if_exists(T::_GetBindColumnEntries)
1954+
#endif //#ifdef _ATL_MODULES
19021955
{
19031956
//Work out the number of bound columns we have
19041957
int nColumns{ 0 };
@@ -1916,15 +1969,19 @@ namespace CODBC
19161969
return nRet;
19171970
}
19181971

1919-
#pragma warning(suppress: 26434)
1972+
#pragma warning(suppress: 26434 26440 26460)
19201973
SQLRETURN BindParameters(_In_ CStatement& statement)
19211974
{
19221975
UNREFERENCED_PARAMETER(statement);
19231976

19241977
//What will be the return value from this method
19251978
SQLRETURN nRet{ SQL_SUCCESS };
19261979

1980+
#ifdef _ATL_MODULES
1981+
if constexpr (_Has_GetBindParametersEntries<T, SQLRETURN(CODBC::CStatement*, int*, std::vector<SQLLEN>*)>::value)
1982+
#else
19271983
__if_exists(T::_GetBindParametersEntries)
1984+
#endif //#ifdef _ATL_MODULES
19281985
{
19291986
//Work out the number of bound parameters we have
19301987
int nColumns{ 0 };
@@ -2136,32 +2193,32 @@ namespace CODBC
21362193
return nRet;
21372194
}
21382195

2139-
_NODISCARD String GetColumnName(_In_ SQLSMALLINT nColumn) const
2196+
[[nodiscard]] String GetColumnName(_In_ SQLSMALLINT nColumn) const
21402197
{
21412198
return this->m_ColumnNames[nColumn - 1]; //nColumn is 1 based
21422199
}
21432200

2144-
_NODISCARD SQLSMALLINT GetColumnType(_In_ SQLSMALLINT nColumn) const
2201+
[[nodiscard]] SQLSMALLINT GetColumnType(_In_ SQLSMALLINT nColumn) const
21452202
{
21462203
return this->m_ColumnDataTypes[nColumn - 1]; //nColumn is 1 based
21472204
}
21482205

2149-
_NODISCARD SQLULEN GetColumnSize(_In_ SQLSMALLINT nColumn) const
2206+
[[nodiscard]] SQLULEN GetColumnSize(_In_ SQLSMALLINT nColumn) const
21502207
{
21512208
return this->m_ColumnSizes[nColumn - 1]; //nColumn is 1 based
21522209
}
21532210

2154-
_NODISCARD SQLSMALLINT GetColumnDecimalDigits(_In_ SQLSMALLINT nColumn) const
2211+
[[nodiscard]] SQLSMALLINT GetColumnDecimalDigits(_In_ SQLSMALLINT nColumn) const
21552212
{
21562213
return this->m_ColumnDecimalDigits[nColumn - 1]; //nColumn is 1 based
21572214
}
21582215

2159-
_NODISCARD SQLSMALLINT GetColumnNullables(_In_ SQLSMALLINT nColumn) const
2216+
[[nodiscard]] SQLSMALLINT GetColumnNullables(_In_ SQLSMALLINT nColumn) const
21602217
{
21612218
return this->m_ColumnNullables[nColumn - 1]; //nColumn is 1 based
21622219
}
21632220

2164-
_NODISCARD SQLSMALLINT GetColumnNo(_In_z_ LPCTSTR pszColumnName) const
2221+
[[nodiscard]] SQLSMALLINT GetColumnNo(_In_z_ LPCTSTR pszColumnName) const
21652222
{
21662223
#pragma warning(suppress: 26489)
21672224
const auto iter{ std::find_if(this->m_ColumnNames.begin(), this->m_ColumnNames.end(), [pszColumnName](const String& element)

WebSearchEngine.rc

0 Bytes
Binary file not shown.

WebSearchEngineExt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ bool ProcessHTML(CWebSearchEngineDlg* pWebSearchEngineDlg, const std::string& lp
227227
if (pHtmlFile.is_open())
228228
{
229229
pHtmlFile.seekg(0, std::ios::end);
230-
pHtmlContent.reserve(pHtmlFile.tellg());
230+
pHtmlContent.reserve(static_cast<unsigned int>(pHtmlFile.tellg()));
231231
pHtmlFile.seekg(0, std::ios::beg);
232232

233233
pHtmlContent.assign((std::istreambuf_iterator<char>(pHtmlFile)),

x64/Release/WebSearchEngine.exe

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)