mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/DBLayer: Refine field type checks in Field::GetXXX methods. Should give us logs of wrong GetXXX calls for a certain type without having to dig trough valgrind logs.
This commit is contained in:
@@ -41,11 +41,12 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_TINY))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetUInt8() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetUInt8() on non-tinyint field.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<uint8*>(data.value);
|
||||
@@ -58,12 +59,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_TINY))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GeInt8() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetInt8() on non-tinyint field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<int8*>(data.value);
|
||||
return static_cast<int8>(atol((char*)data.value));
|
||||
@@ -75,12 +77,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetUInt16() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetUInt16() on non-smallint field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<uint16*>(data.value);
|
||||
return static_cast<uint16>(atol((char*)data.value));
|
||||
@@ -92,12 +95,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetInt16() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetInt16() on non-smallint field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<int16*>(data.value);
|
||||
return static_cast<int16>(atol((char*)data.value));
|
||||
@@ -109,12 +113,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetUInt32() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetUInt32() on non-(medium)int field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<uint32*>(data.value);
|
||||
return static_cast<uint32>(atol((char*)data.value));
|
||||
@@ -126,12 +131,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetInt32() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetInt32() on non-(medium)int field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<int32*>(data.value);
|
||||
return static_cast<int32>(atol((char*)data.value));
|
||||
@@ -143,12 +149,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetUInt64() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetUInt64() on non-bigint field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<uint64*>(data.value);
|
||||
return static_cast<uint64>(atol((char*)data.value));
|
||||
@@ -160,12 +167,13 @@ class Field
|
||||
return 0;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetInt64() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetInt64() on non-bigint field.");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<int64*>(data.value);
|
||||
return static_cast<int64>(strtol((char*)data.value, NULL, 10));
|
||||
@@ -177,12 +185,13 @@ class Field
|
||||
return 0.0f;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_FLOAT))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetFloat() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetFloat() on non-float field.");
|
||||
return 0.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<float*>(data.value);
|
||||
return static_cast<float>(atof((char*)data.value));
|
||||
@@ -194,12 +203,13 @@ class Field
|
||||
return 0.0f;
|
||||
|
||||
#ifdef TRINITY_DEBUG
|
||||
if (!IsNumeric())
|
||||
if (!IsType(MYSQL_TYPE_FLOAT))
|
||||
{
|
||||
sLog->outSQLDriver("Error: GetDouble() on non-numeric field.");
|
||||
sLog->outSQLDriver("Warning: GetDouble() on non-double field.");
|
||||
return 0.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.raw)
|
||||
return *reinterpret_cast<double*>(data.value);
|
||||
return static_cast<double>(atof((char*)data.value));
|
||||
@@ -316,6 +326,11 @@ class Field
|
||||
}
|
||||
}
|
||||
|
||||
bool IsType(enum_field_types type) const
|
||||
{
|
||||
return data.type == type;
|
||||
}
|
||||
|
||||
bool IsNumeric() const
|
||||
{
|
||||
return (data.type == MYSQL_TYPE_TINY ||
|
||||
|
||||
Reference in New Issue
Block a user