From b8e86b9b7a0983b3bc610513531944e68c01c911 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 13 Sep 2015 11:13:04 +0200 Subject: Core/DBLayer: Allowed using GetDouble for SUM results instead of requiring string conversions (cherry picked from commit 3109ab2da08d094df97724355bff681d7951e576) --- src/server/database/Database/Field.h | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/server/database/Database/Field.h') diff --git a/src/server/database/Database/Field.h b/src/server/database/Database/Field.h index 42a842e6283..72364f2c034 100644 --- a/src/server/database/Database/Field.h +++ b/src/server/database/Database/Field.h @@ -23,6 +23,36 @@ #include +/** + @class Field + + @brief Class used to access individual fields of database query result + + Guideline on field type matching: + + | MySQL type | method to use | + |------------------------|----------------------------------------| + | TINYINT | GetBool, GetInt8, GetUInt8 | + | SMALLINT | GetInt16, GetUInt16 | + | MEDIUMINT, INT | GetInt32, GetUInt32 | + | BIGINT | GetInt64, GetUInt64 | + | FLOAT | GetFloat | + | DOUBLE, DECIMAL | GetDouble | + | CHAR, VARCHAR, | GetCString, GetString | + | TINYTEXT, MEDIUMTEXT, | GetCString, GetString | + | TEXT, LONGTEXT | GetCString, GetString | + | TINYBLOB, MEDIUMBLOB, | GetBinary, GetString | + | BLOB, LONGBLOB | GetBinary, GetString | + | BINARY, VARBINARY | GetBinary | + + Return types of aggregate functions: + + | Function | Type | + |----------|-------------------| + | MIN, MAX | Same as the field | + | SUM, AVG | DECIMAL | + | COUNT | BIGINT | +*/ class Field { friend class ResultSet; @@ -214,15 +244,15 @@ class Field return 0.0f; #ifdef TRINITY_DEBUG - if (!IsType(MYSQL_TYPE_DOUBLE)) + if (!IsType(MYSQL_TYPE_DOUBLE) && !IsType(MYSQL_TYPE_NEWDECIMAL)) { - TC_LOG_WARN("sql.sql", "Warning: GetDouble() on non-double field %s.%s (%s.%s) at index %u. Using type: %s.", + TC_LOG_WARN("sql.sql", "Warning: GetDouble() on non-double/non-decimal field %s.%s (%s.%s) at index %u. Using type: %s.", meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type); return 0.0f; } #endif - if (data.raw) + if (data.raw && !IsType(MYSQL_TYPE_NEWDECIMAL)) return *reinterpret_cast(data.value); return static_cast(atof((char*)data.value)); } -- cgit v1.2.3