From cfd7f52a2f957b6984cdb38b00422f53125598f3 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 5 Oct 2025 14:34:47 +0200 Subject: [PATCH 1/2] 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(sqlite3 &,Sqlite3::Statement &,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(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>(sqlite3 &,sqlite3_stmt &,std::tuple &)' 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 ] D:\dev\openmw\components/sqlite3/request.hpp(190): note: see reference to function template instantiation 'void Sqlite3::copyColumn(sqlite3 &,sqlite3_stmt &,int,int,T &)' being compiled with [ T=DetourNavigator::TileId ] --- components/sqlite3/request.hpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/components/sqlite3/request.hpp b/components/sqlite3/request.hpp index d4737a41f9..63f15bf33e 100644 --- a/components/sqlite3/request.hpp +++ b/components/sqlite3/request.hpp @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -19,6 +20,12 @@ namespace Sqlite3 { + template + 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 + template 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(sqlite3_column_int64(&statement, index)); return; + case SQLITE_NULL: + value = std::decay_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 + inline auto copyColumn(sqlite3& /*db*/, sqlite3_stmt& statement, int index, int type, T& value) + { + switch (type) + { case SQLITE_FLOAT: value = static_cast(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 + 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) From d171915b6a5c94994b1100bd0b8433f9e7fdd16d Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 5 Oct 2025 14:46:17 +0200 Subject: [PATCH 2/2] Fix error message --- components/sqlite3/request.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sqlite3/request.hpp b/components/sqlite3/request.hpp index 63f15bf33e..b77e1a5ce8 100644 --- a/components/sqlite3/request.hpp +++ b/components/sqlite3/request.hpp @@ -100,7 +100,7 @@ namespace Sqlite3 { if (type != SQLITE_NULL) 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"); + + " that does not match expected output type: SQLITE_NULL"); value = nullptr; }