From 548ed703092a28045f9348bc4918e050938268d5 Mon Sep 17 00:00:00 2001 From: Barbz Date: Thu, 5 Mar 2020 19:35:49 +0100 Subject: feat: New page "MySQL types (C++)" ported from TC (#191) Co-authored-by: Barbz --- _includes/azerothcore/sidebar.html | 1 + docs/MySQLtypesC++.md | 214 +++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 docs/MySQLtypesC++.md diff --git a/_includes/azerothcore/sidebar.html b/_includes/azerothcore/sidebar.html index 147fffd..19fbfbd 100644 --- a/_includes/azerothcore/sidebar.html +++ b/_includes/azerothcore/sidebar.html @@ -45,6 +45,7 @@
  • Coding Standards
  • Project Versioning
  • Sql Versioning
  • +
  • MySQL types (C++)
  • Hooks Bash
  • Hooks Cmake
  • Hooks C++
  • diff --git a/docs/MySQLtypesC++.md b/docs/MySQLtypesC++.md new file mode 100644 index 0000000..06f2e8f --- /dev/null +++ b/docs/MySQLtypesC++.md @@ -0,0 +1,214 @@ +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Mapping from types used in SQL queries
    +

    MySQL type

    +
    Core type + Example codeVariable operators
    bigint(20)int64int64 val = fields[n].GetInt64();%I64d       (Capital i)
    bigint(20) unsigneduint64uint64 val = fields[n].GetUInt64(); + %I64u       (Capital i)
    int(11)int32int32 val = fields[n].GetInt32(); + %u
    int(10) unsigneduint32uint32 val = fields[n].GetUInt32(); + %u
    mediumint(8)int32int32 val = fields[n].GetInt32(); + %u
    mediumint(8) unsigneduint32uint32 val = fields[n].GetUInt32(); + %u
    smallint(6)int16int16 val = fields[n].GetInt16(); +  
    smallint(5) unsigneduint16uint16 val = fields[n].GetUInt16(); +  
    tinyint(4)int8int16 val = fields[n].GetInt16(); +  
    tinyint(3) unsigneduint8uint8 val = fields[n].GetUInt8(); +  
    floatfloatfloat val = fields[n].GetFloat(); 
    float unsigned 
    doubledoubledouble val = fields[n].GetDouble(); 
    double unsigned 
    text +

    string (std::string)

    +

    or

    +

    cstring (char const*)

    +
    +

    std::string text = fields[n].GetString();

    +

    char const* text = fields[n].GetCString();

    +
    %s
    longtext%s
    tinytext%s
    char(k)%s
    varchar(k)%s
    blob%s
    COUNT(x)uint64uint64 count = fields[n].GetUInt64(); + %UI64FMT*
    MAX(x)uint32 or int32 +

    uint32 minmax = fields[n].GetUInt32();

    +

    int32 minmax = fields[n].GetInt32();

    +
    %u
    MIN(x)%u
    SUM(x) +

    string (std::string)

    +

    or

    +

    cstring (char const*)

    +
    +

    int sum;

    +

    if (const char* ch = fields[n].GetCString())

    +

    sum = atoi(ch);

    +
    +

    %s

    +

     

    +

    %s

    +
    UNIX_TIMESTAMP(x)uint64uint64 unix_time = fields[n].GetUInt64(); +

     

    +
    +
    +

    1* %UI64FMT does not work with acore_string

    +

     

    +

     

    +
    +
    Example
    +
    +
    +
    + +```cpp +// 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()); +``` -- cgit