mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-16 19:46:37 +00:00
Fix C4244 MSVC warning in Sqlite3::copyColumn
Make sure sqlite3_column_double is not called for int64_t and other integral types and sqlite3_column_int64 is not called for floating point types. [363/1189] Building CXX object components\CMakeFiles\components.dir\RelWithDebInfo\detournavigator\navmeshdb.cpp.obj D:\dev\openmw\components/sqlite3/request.hpp(109): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data with [ T=int64_t ] D:\dev\openmw\components/sqlite3/request.hpp(109): note: the template instantiation context (the oldest one first) is D:\dev\openmw\components\detournavigator\navmeshdb.cpp(198): note: see reference to function template instantiation 'I Sqlite3::request<DetourNavigator::DbQueries::GetMaxTileId,DetourNavigator::TileId*,>(sqlite3 &,Sqlite3::Statement<DetourNavigator::DbQueries::GetMaxTileId> &,I,size_t)' being compiled with [ I=DetourNavigator::TileId * ] D:\dev\openmw\components/sqlite3/request.hpp(262): note: see reference to function template instantiation 'void Sqlite3::getRow<DetourNavigator::TileId>(sqlite3 &,sqlite3_stmt &,T &)' being compiled with [ T=DetourNavigator::TileId ] D:\dev\openmw\components/sqlite3/request.hpp(210): note: see reference to function template instantiation 'void Sqlite3::getColumns<std::tuple<T &>>(sqlite3 &,sqlite3_stmt &,std::tuple<T &> &)' being compiled with [ T=DetourNavigator::TileId ] D:\dev\openmw\components/sqlite3/request.hpp(203): note: see reference to function template instantiation 'void Sqlite3::getColumnsImpl<1,T>(sqlite3 &,sqlite3_stmt &,T &)' being compiled with [ T=std::tuple<DetourNavigator::TileId &> ] D:\dev\openmw\components/sqlite3/request.hpp(190): note: see reference to function template instantiation 'void Sqlite3::copyColumn<T>(sqlite3 &,sqlite3_stmt &,int,int,T &)' being compiled with [ T=DetourNavigator::TileId ]
This commit is contained in:
parent
ef05e089ab
commit
cfd7f52a2f
1 changed files with 28 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <concepts>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
|
@ -19,6 +20,12 @@
|
|||
|
||||
namespace Sqlite3
|
||||
{
|
||||
template <class T>
|
||||
concept StrongTypedef = requires(T v)
|
||||
{
|
||||
v.mValue;
|
||||
};
|
||||
|
||||
inline void bindParameter(sqlite3& db, sqlite3_stmt& stmt, int index, int value)
|
||||
{
|
||||
if (const int ec = sqlite3_bind_int(&stmt, index, value); ec != SQLITE_OK)
|
||||
|
@ -97,7 +104,7 @@ namespace Sqlite3
|
|||
value = nullptr;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
template <std::integral T>
|
||||
inline auto copyColumn(sqlite3& /*db*/, sqlite3_stmt& statement, int index, int type, T& value)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -105,6 +112,19 @@ namespace Sqlite3
|
|||
case SQLITE_INTEGER:
|
||||
value = static_cast<T>(sqlite3_column_int64(&statement, index));
|
||||
return;
|
||||
case SQLITE_NULL:
|
||||
value = std::decay_t<T>{};
|
||||
return;
|
||||
}
|
||||
throw std::logic_error("Type of column " + std::to_string(index) + " is " + sqliteTypeToString(type)
|
||||
+ " that does not match expected output type: SQLITE_INTEGER or SQLITE_NULL");
|
||||
}
|
||||
|
||||
template <std::floating_point T>
|
||||
inline auto copyColumn(sqlite3& /*db*/, sqlite3_stmt& statement, int index, int type, T& value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SQLITE_FLOAT:
|
||||
value = static_cast<T>(sqlite3_column_double(&statement, index));
|
||||
return;
|
||||
|
@ -113,7 +133,13 @@ namespace Sqlite3
|
|||
return;
|
||||
}
|
||||
throw std::logic_error("Type of column " + std::to_string(index) + " is " + sqliteTypeToString(type)
|
||||
+ " that does not match expected output type: SQLITE_INTEGER or SQLITE_FLOAT or SQLITE_NULL");
|
||||
+ " that does not match expected output type: SQLITE_FLOAT or SQLITE_NULL");
|
||||
}
|
||||
|
||||
template <StrongTypedef T>
|
||||
inline auto copyColumn(sqlite3& db, sqlite3_stmt& statement, int index, int type, T& value)
|
||||
{
|
||||
return copyColumn(db, statement, index, type, value.mValue);
|
||||
}
|
||||
|
||||
inline void copyColumn(sqlite3& db, sqlite3_stmt& statement, int index, int type, std::string& value)
|
||||
|
|
Loading…
Reference in a new issue