Example #1
0
std::string CreateDumpString(char const* tableName, QueryResult_AutoPtr result)
{
    if (!tableName || !result) return "";
    std::ostringstream ss;
    ss << "INSERT INTO "<< _TABLE_SIM_ << tableName << _TABLE_SIM_ << " VALUES (";
    Field *fields = result->Fetch();
    for (uint32 i = 0; i < result->GetFieldCount(); ++i)
    {
        if (i == 0) ss << "'";
        else ss << ", '";

        std::string s = fields[i].GetCppString();
        CharacterDatabase.escape_string(s);
        ss << s;

        ss << "'";
    }
    ss << ");";
    return ss.str();
}
Example #2
0
// Writing - High-level functions
bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type)
{
    GUIDs const* guids = NULL;
    char const* fieldname = NULL;

    switch (type)
    {
    case DTT_ITEM:
        fieldname = "guid";
        guids = &items;
        break;
    case DTT_ITEM_GIFT:
        fieldname = "item_guid";
        guids = &items;
        break;
    case DTT_PET:
        fieldname = "owner";
        break;
    case DTT_PET_TABLE:
        fieldname = "guid";
        guids = &pets;
        break;
    case DTT_MAIL:
        fieldname = "receiver";
        break;
    case DTT_MAIL_ITEM:
        fieldname = "mail_id";
        guids = &mails;
        break;
    default:
        fieldname = "guid";
        break;
    }

    // for guid set stop if set is empty
    if (guids && guids->empty())
        return true;                                        // nothing to do

    // setup for guids case start position
    GUIDs::const_iterator guids_itr;
    if (guids)
        guids_itr = guids->begin();

    do
    {
        std::string wherestr;

        if (guids)                                           // set case, get next guids string
            wherestr = GenerateWhereStr(fieldname,*guids,guids_itr);
        else                                                // not set case, get single guid string
            wherestr = GenerateWhereStr(fieldname,guid);

        QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
        if (!result)
            return true;

        do
        {
            // collect guids
            switch (type)
            {
            case DTT_INVENTORY:
                StoreGUID(result,3,items);
                break;       // item guid collection (character_inventory.item)
            case DTT_PET:
                StoreGUID(result,0,pets);
                break;       // pet petnumber collection (character_pet.id)
            case DTT_MAIL:
                StoreGUID(result,0,mails);              // mail id collection (mail.id)
            case DTT_MAIL_ITEM:
                StoreGUID(result,1,items);
                break;       // item guid collection (mail_items.item_guid)
            case DTT_CHARACTER:
            {
                if (result->GetFieldCount() <= 67)      // avoid crashes on next check
                    return true;
                if (result->Fetch()[67].GetUInt32())    // characters.deleteInfos_Account - if filled error
                    return false;
                break;
            }
            default:
                break;
            }

            dump += CreateDumpString(tableTo, result);
            dump += "\n";
        }
        while (result->NextRow());
    }
    while (guids && guids_itr != guids->end());              // not set case iterate single time, set case iterate for all guids
    return true;
}