1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-15 12:56:36 +00:00

Merge branch 'fix_copy_column_warning' into 'master'

Fix C4244 MSVC warning in Sqlite3::copyColumn

See merge request OpenMW/openmw!4939
This commit is contained in:
Alexei Kotov 2025-10-11 07:11:29 +03:00
commit 39b22cbcdf

View file

@ -6,6 +6,7 @@
#include <sqlite3.h> #include <sqlite3.h>
#include <concepts>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
@ -19,6 +20,12 @@
namespace Sqlite3 namespace Sqlite3
{ {
template <class T>
concept StrongTypedef = requires(T v)
{
v.mValue;
};
inline void bindParameter(sqlite3& db, sqlite3_stmt& stmt, int index, int value) 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) if (const int ec = sqlite3_bind_int(&stmt, index, value); ec != SQLITE_OK)
@ -93,11 +100,11 @@ namespace Sqlite3
{ {
if (type != SQLITE_NULL) if (type != SQLITE_NULL)
throw std::logic_error("Type of column " + std::to_string(index) + " is " + sqliteTypeToString(type) 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; value = nullptr;
} }
template <class T> template <std::integral T>
inline auto copyColumn(sqlite3& /*db*/, sqlite3_stmt& statement, int index, int type, T& value) inline auto copyColumn(sqlite3& /*db*/, sqlite3_stmt& statement, int index, int type, T& value)
{ {
switch (type) switch (type)
@ -105,6 +112,19 @@ namespace Sqlite3
case SQLITE_INTEGER: case SQLITE_INTEGER:
value = static_cast<T>(sqlite3_column_int64(&statement, index)); value = static_cast<T>(sqlite3_column_int64(&statement, index));
return; 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: case SQLITE_FLOAT:
value = static_cast<T>(sqlite3_column_double(&statement, index)); value = static_cast<T>(sqlite3_column_double(&statement, index));
return; return;
@ -113,7 +133,13 @@ namespace Sqlite3
return; return;
} }
throw std::logic_error("Type of column " + std::to_string(index) + " is " + sqliteTypeToString(type) 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) inline void copyColumn(sqlite3& db, sqlite3_stmt& statement, int index, int type, std::string& value)