232{
233 int32_t changes = 0;
234
236
238
239 std::shared_ptr<boost::mysql::tcp_ssl_connection> conn =
sZone->get_database_connection();
240
241 try {
242 boost::mysql::statement stmt = conn->prepare_statement("DELETE FROM `storage` WHERE `account_id` = ? AND `storage_id` = ?");
244 boost::mysql::results results;
245 conn->execute(b1, results);
246
247 boost::format fmt_ctx = boost::format("INSERT INTO `storage` (`account_id`, `storage_id`, `item_id`, `amount`, `equip_location_mask`,"
248 "`is_identified`, `refine_level`, `element_type`, `slot_item_id_0`, `slot_item_id_1`, `slot_item_id_2`, `slot_item_id_3`, `opt_idx0`, `opt_val0`,"
249 "`opt_idx1`, `opt_val1`, `opt_idx2`, `opt_val2`, `opt_idx3`, `opt_val3`, `opt_idx4`, `opt_val4`, `hire_expire_date`, `is_favorite`, `is_broken`, `bind_type`, `unique_id`"
250 "VALUES ");
251
254 std::shared_ptr<const item_entry_data> mit = *mit_i;
255
256 if (mit == nullptr)
257 continue;
258
260 std::string str = fmt_ctx.str();
261 fmt_ctx = boost::format(str.append(", "));
262 }
263
264 boost::format new_fmt = boost::format("(%1%, %2%, %3%, %4%, %5%, %6%, %7%, %8%, %9%, %10%, %11%, %12%, %13%, %14%, %15%, %16%, %17%, %18%, %19%, %20%, %21%, %22%, %23%, %24%, %25%, %26%, %27%)")
265 %
player()->account()._account_id
267 % (int)mit->item_id
268 % (int)mit->amount
269 % (int)mit->current_equip_location_mask
270 % (int)mit->info.is_identified
271 % (int)mit->refine_level
272 % (int)mit->ele_type
273 % (int)mit->slot_item_id[0]
274 % (int)mit->slot_item_id[1]
275 % (int)mit->slot_item_id[2]
276 % (int)mit->slot_item_id[3]
277 % (int)mit->option_data[0].get_index()
278 % (int)mit->option_data[0].get_value()
279 % (int)mit->option_data[1].get_index()
280 % (int)mit->option_data[1].get_value()
281 % (int)mit->option_data[2].get_index()
282 % (int)mit->option_data[2].get_value()
283 % (int)mit->option_data[3].get_index()
284 % (int)mit->option_data[3].get_value()
285 % (int)mit->option_data[4].get_index()
286 % (int)mit->option_data[4].get_value()
287 % (int)mit->hire_expire_date
288 % (int)mit->info.is_favorite
289 % (int)mit->info.is_broken
290 % (int)mit->bind_type
291 % (int64_t)mit->unique_id;
292
293 std::string str_str = fmt_ctx.str() + new_fmt.str();
294 fmt_ctx = boost::format(str_str);
296 }
297
299 boost::mysql::results results;
300 conn->execute(fmt_ctx.str(), results);
301 }
302
304 }
305 catch (boost::mysql::error_with_diagnostics &error) {
306 HLog(error) <<
"Storage::save:" << error.what();
307 return false;
308 }
309 catch (std::exception& error) {
310 HLog(error) <<
"Storage::save:" << error.what();
311 return false;
312 }
313
314 HLog(info) <<
"Saved Storage (" <<
_name <<
") for (Account ID: " <<
player()->account()._account_id <<
") with " << changes <<
" changes.";
315
316 return changes;
317}
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100