本文整理汇总了C++中DBInsert类的典型用法代码示例。如果您正苦于以下问题:C++ DBInsert类的具体用法?C++ DBInsert怎么用?C++ DBInsert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBInsert类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveItems
bool IOLoginData::saveItems(const Player* player, const ItemBlockList& itemList, DBInsert& query_insert, PropWriteStream& propWriteStream)
{
std::ostringstream ss;
typedef std::pair<Container*, int32_t> containerBlock;
std::queue<containerBlock> queue;
int32_t parentId = 0;
int32_t runningId = 100;
Database* db = Database::getInstance();
for (const auto& it : itemList) {
int32_t pid = it.first;
Item* item = it.second;
++runningId;
propWriteStream.clear();
item->serializeAttr(propWriteStream);
size_t attributesSize;
const char* attributes = propWriteStream.getStream(attributesSize);
ss << player->getGUID() << ',' << pid << ',' << runningId << ',' << item->getID() << ',' << item->getSubType() << ',' << db->escapeBlob(attributes, attributesSize);
if (!query_insert.addRow(ss)) {
return false;
}
if (Container* container = item->getContainer()) {
queue.emplace(container, runningId);
}
}
while (!queue.empty()) {
const containerBlock& cb = queue.front();
Container* container = cb.first;
parentId = cb.second;
queue.pop();
for (Item* item : container->getItemList()) {
++runningId;
Container* subContainer = item->getContainer();
if (subContainer) {
queue.emplace(subContainer, runningId);
}
propWriteStream.clear();
item->serializeAttr(propWriteStream);
size_t attributesSize;
const char* attributes = propWriteStream.getStream(attributesSize);
ss << player->getGUID() << ',' << parentId << ',' << runningId << ',' << item->getID() << ',' << item->getSubType() << ',' << db->escapeBlob(attributes, attributesSize);
if (!query_insert.addRow(ss)) {
return false;
}
}
}
return query_insert.execute();
}
示例2: saveItems
bool IOLoginData::saveItems(const Player* player, const ItemBlockList& itemList, DBInsert& query_insert)
{
std::ostringstream stream;
typedef std::pair<Container*, int32_t> containerBlock;
std::list<containerBlock> stack;
int32_t parentId = 0;
int32_t runningId = 100;
Database* db = Database::getInstance();
for (ItemBlockList::const_iterator it = itemList.begin(); it != itemList.end(); ++it) {
int32_t pid = it->first;
Item* item = it->second;
++runningId;
uint32_t attributesSize = 0;
PropWriteStream propWriteStream;
item->serializeAttr(propWriteStream);
const char* attributes = propWriteStream.getStream(attributesSize);
stream << player->getGUID() << ',' << pid << ',' << runningId << ',' << item->getID() << ',' << (int32_t)item->getSubType() << ',' << db->escapeBlob(attributes, attributesSize);
if (!query_insert.addRow(stream)) {
return false;
}
if (Container* container = item->getContainer()) {
stack.emplace_back(container, runningId);
}
}
while (!stack.empty()) {
const containerBlock& cb = stack.front();
Container* container = cb.first;
parentId = cb.second;
stack.pop_front();
for (Item* item : container->getItemList()) {
++runningId;
Container* subContainer = item->getContainer();
if (subContainer) {
stack.emplace_back(subContainer, runningId);
}
uint32_t attributesSize = 0;
PropWriteStream propWriteStream;
item->serializeAttr(propWriteStream);
const char* attributes = propWriteStream.getStream(attributesSize);
stream << player->getGUID() << ',' << parentId << ',' << runningId << ',' << item->getID() << ',' << (int32_t)item->getSubType() << ',' << db->escapeBlob(attributes, attributesSize);
if (!query_insert.addRow(stream)) {
return false;
}
}
}
return query_insert.execute();
}
示例3: OTSYS_TIME
bool IOMapSerialize::saveMap()
{
int64_t start = OTSYS_TIME();
Database* db = Database::getInstance();
std::ostringstream query;
//Start the transaction
DBTransaction transaction;
if (!transaction.begin()) {
return false;
}
//clear old tile data
if (!db->executeQuery("DELETE FROM `tile_store`")) {
return false;
}
DBInsert stmt;
stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `data`) VALUES ");
PropWriteStream stream;
for (const auto& it : Houses::getInstance().getHouses()) {
//save house items
House* house = it.second;
for (HouseTile* tile : house->getTiles()) {
saveTile(stream, tile);
size_t attributesSize;
const char* attributes = stream.getStream(attributesSize);
if (attributesSize > 0) {
query << house->getId() << ',' << db->escapeBlob(attributes, attributesSize);
if (!stmt.addRow(query)) {
return false;
}
}
stream.clear();
}
}
if (!stmt.execute()) {
return false;
}
//End the transaction
bool success = transaction.commit();
std::cout << "> Saved house items in: " <<
(OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
return success;
}
示例4: saveHouseBinary
bool IOMapSerialize::saveHouseBinary(Database* db, DBInsert& stmt, House* house)
{
PropWriteStream stream;
for(HouseTileList::iterator tit = house->getHouseTileBegin(); tit != house->getHouseTileEnd(); ++tit)
{
if(!saveTile(stream, *tit))
continue;
}
uint32_t attributesSize = 0;
const char* attributes = stream.getStream(attributesSize);
if(!attributesSize)
return true;
DBQuery query;
query << house->getId() << ", " << g_config.getNumber(ConfigManager::WORLD_ID)
<< ", " << db->escapeBlob(attributes, attributesSize);
return stmt.addRow(query);
}
示例5: VALUES
bool IOMapSerialize::saveHouseInfo()
{
Database* db = Database::getInstance();
DBTransaction transaction;
if (!transaction.begin()) {
return false;
}
if (!db->executeQuery("DELETE FROM `house_lists`")) {
return false;
}
std::ostringstream query;
for (const auto& it : Houses::getInstance().getHouses()) {
House* house = it.second;
query << "SELECT `id` FROM `houses` WHERE `id` = " << house->getId();
DBResult* result = db->storeQuery(query.str());
if (result) {
db->freeResult(result);
query.str("");
query << "UPDATE `houses` SET `owner` = " << house->getOwner() << ", `paid` = " << house->getPaidUntil() << ", `warnings` = " << house->getPayRentWarnings() << ", `name` = " << db->escapeString(house->getName()) << ", `town_id` = " << house->getTownId() << ", `rent` = " << house->getRent() << ", `size` = " << house->getTiles().size() << ", `beds` = " << house->getBedCount() << " WHERE `id` = " << house->getId();
} else {
query.str("");
query << "INSERT INTO `houses` (`id`, `owner`, `paid`, `warnings`, `name`, `town_id`, `rent`, `size`, `beds`) VALUES (" << house->getId() << ',' << house->getOwner() << ',' << house->getPaidUntil() << ',' << house->getPayRentWarnings() << ',' << db->escapeString(house->getName()) << ',' << house->getTownId() << ',' << house->getRent() << ',' << house->getTiles().size() << ',' << house->getBedCount() << ')';
}
db->executeQuery(query.str());
query.str("");
}
DBInsert stmt;
stmt.setQuery("INSERT INTO `house_lists` (`house_id` , `listid` , `list`) VALUES ");
for (const auto& it : Houses::getInstance().getHouses()) {
House* house = it.second;
std::string listText;
if (house->getAccessList(GUEST_LIST, listText) && !listText.empty()) {
query << house->getId() << ',' << GUEST_LIST << ',' << db->escapeString(listText);
if (!stmt.addRow(query)) {
return false;
}
listText.clear();
}
if (house->getAccessList(SUBOWNER_LIST, listText) && !listText.empty()) {
query << house->getId() << ',' << SUBOWNER_LIST << ',' << db->escapeString(listText);
if (!stmt.addRow(query)) {
return false;
}
listText.clear();
}
for (Door* door : house->getDoors()) {
if (door->getAccessList(listText) && !listText.empty()) {
query << house->getId() << ',' << door->getDoorId() << ',' << db->escapeString(listText);
if (!stmt.addRow(query)) {
return false;
}
listText.clear();
}
}
}
if (!stmt.execute()) {
return false;
}
return transaction.commit();
}
示例6: time
//.........这里部分代码省略.........
query << "`skill_axe` = " << player->skills[SKILL_AXE][SKILL_LEVEL] << ',';
query << "`skill_axe_tries` = " << player->skills[SKILL_AXE][SKILL_TRIES] << ',';
query << "`skill_dist` = " << player->skills[SKILL_DIST][SKILL_LEVEL] << ',';
query << "`skill_dist_tries` = " << player->skills[SKILL_DIST][SKILL_TRIES] << ',';
query << "`skill_shielding` = " << player->skills[SKILL_SHIELD][SKILL_LEVEL] << ',';
query << "`skill_shielding_tries` = " << player->skills[SKILL_SHIELD][SKILL_TRIES] << ',';
query << "`skill_fishing` = " << player->skills[SKILL_FISH][SKILL_LEVEL] << ',';
query << "`skill_fishing_tries` = " << player->skills[SKILL_FISH][SKILL_TRIES] << ',';
if (!player->isOffline()) {
query << "`onlinetime` = `onlinetime` + " << (time(nullptr) - player->lastLoginSaved) << ',';
}
query << "`blessings` = " << player->blessings;
query << " WHERE `id` = " << player->getGUID();
DBTransaction transaction;
if (!transaction.begin()) {
return false;
}
if (!db->executeQuery(query.str())) {
return false;
}
// learned spells
query.str("");
query << "DELETE FROM `player_spells` WHERE `player_id` = " << player->getGUID();
if (!db->executeQuery(query.str())) {
return false;
}
query.str("");
DBInsert stmt;
stmt.setQuery("INSERT INTO `player_spells` (`player_id`, `name` ) VALUES ");
for (LearnedInstantSpellList::const_iterator it = player->learnedInstantSpellList.begin();
it != player->learnedInstantSpellList.end(); ++it) {
query << player->getGUID() << ',' << db->escapeString(*it);
if (!stmt.addRow(query)) {
return false;
}
}
if (!stmt.execute()) {
return false;
}
//item saving
query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID();
if (!db->executeQuery(query.str())) {
return false;
}
stmt.setQuery("INSERT INTO `player_items` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES ");
ItemBlockList itemList;
for (int32_t slotId = 1; slotId <= 10; ++slotId) {
Item* item = player->inventory[slotId];
if (item) {
itemList.emplace_back(slotId, item);
}
}
if (!saveItems(player, itemList, stmt)) {
示例7: saveItems
bool IOPlayer::saveItems(Player* player, const ItemBlockList& itemList, DBInsert& query_insert)
{
std::list<Container*> listContainer;
std::stringstream stream;
typedef std::pair<Container*, int32_t> containerBlock;
std::list<containerBlock> stack;
int32_t parentId = 0;
int32_t runningId = 100;
Database* db = Database::instance();
Item* item;
int32_t pid;
for(ItemBlockList::const_iterator it = itemList.begin(); it != itemList.end(); ++it){
pid = it->first;
item = it->second;
++runningId;
uint32_t attributesSize;
PropWriteStream propWriteStream;
item->serializeAttr(propWriteStream);
const char* attributes = propWriteStream.getStream(attributesSize);
stream << player->getGUID() << ", " << pid << ", " << runningId << ", " << item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize);
if(!query_insert.addRow(stream)){
return false;
}
if(Container* container = item->getContainer()){
stack.push_back(containerBlock(container, runningId));
}
}
while(stack.size() > 0){
const containerBlock& cb = stack.front();
Container* container = cb.first;
parentId = cb.second;
stack.pop_front();
for(uint32_t i = 0; i < container->size(); ++i){
++runningId;
item = container->getItem(i);
if(Container* sub = item->getContainer()){
stack.push_back(containerBlock(sub, runningId));
}
uint32_t attributesSize;
PropWriteStream propWriteStream;
item->serializeAttr(propWriteStream);
const char* attributes = propWriteStream.getStream(attributesSize);
stream << player->getGUID() << ", " << parentId << ", " << runningId << ", " << item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize);
if(!query_insert.addRow(stream))
return false;
}
}
return true;
}