MySQL types (C++)
Mapping from types used in SQL queries | |||
|---|---|---|---|
MySQL type | Trinity type | Example code | Variable operators |
bigint(20) | int64 |
| %I64d (Capital i) |
bigint(20) unsigned | uint64 |
| %I64u (Capital i) |
int(11) | int32 |
| %u |
int(10) unsigned | uint32 |
| %u |
mediumint(8) | int32 |
| %u |
mediumint(8) unsigned | uint32 |
| %u |
smallint(6) | int16 |
|
|
smallint(5) unsigned | uint16 |
|
|
tinyint(4) | int8 |
|
|
tinyint(3) unsigned | uint8 |
|
|
float | float |
|
|
float unsigned |
| ||
double | double |
|
|
double unsigned |
| ||
text | string (std::string) or cstring (char const*) |
| %s |
longtext | %s | ||
tinytext | %s | ||
char(k) | %s | ||
varchar(k) | %s | ||
blob | %s | ||
COUNT(x) | uint64 |
| %UI64FMT* |
MAX(x) | uint32 or int32 |
| %u |
MIN(x) | %u | ||
SUM(x) | string (std::string) or cstring (char const*) |
| %s
%s |
UNIX_TIMESTAMP(x) | uint64 |
|
|
1* %UI64FMT does not work with trinity_string
Example
// world database query 0 1 2 3 4
QueryResult result = WorldDatabase.Query("SELECT guid, entry, name, period, ScriptName FROM transports");
do
{
Field* fields = result->Fetch();
uint32 lowguid = fields[0].GetUInt32();
uint32 entry = fields[1].GetUInt32();
std::string name = fields[2].GetString();
uint32 period = fields[3].GetUInt32();
uint32 scriptId = sObjectMgr->GetScriptId(fields[4].GetCString());
// ...
}
while (result->NextRow());