diff options
author | Shauren <shauren.trinity@gmail.com> | 2015-09-13 11:13:04 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2015-10-31 18:25:40 +0100 |
commit | b8e86b9b7a0983b3bc610513531944e68c01c911 (patch) | |
tree | 0fc521b0926310ae2bb90bae18c867e4b56e47b9 /src/server/database/Database/Field.h | |
parent | a410072d6db23769bcf46609c2a540b545d10e73 (diff) |
Core/DBLayer: Allowed using GetDouble for SUM results instead of requiring string conversions
(cherry picked from commit 3109ab2da08d094df97724355bff681d7951e576)
Diffstat (limited to 'src/server/database/Database/Field.h')
-rw-r--r-- | src/server/database/Database/Field.h | 36 |
1 files changed, 33 insertions, 3 deletions
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 <mysql.h> +/** + @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<double*>(data.value); return static_cast<double>(atof((char*)data.value)); } |