444{
445 std::string configTempDir =
sConfigMgr->GetOption<std::string>(
"TempDir",
"");
446
447 auto tempDir = configTempDir.empty() ? std::filesystem::temp_directory_path().string() : configTempDir;
448
450
451 std::string confFileName = "mysql_ac.conf";
452
453 std::ofstream outfile (tempDir + confFileName);
454
455 outfile << "[client]\npassword = \"" << password << '"' << std::endl;
456
457 outfile.close();
458
459 std::vector<std::string> args;
460 args.reserve(9);
461
462 args.emplace_back("--defaults-extra-file="+tempDir + confFileName+"");
463
464
465 args.emplace_back("-h" + host);
466 args.emplace_back("-u" + user);
467
468
469#ifdef _WIN32
470
471 if (host == ".")
472 args.emplace_back("--protocol=PIPE");
473 else
474 args.emplace_back("-P" + port_or_socket);
475
476#else
477
478 if (!std::isdigit(port_or_socket[0]))
479 {
480
481 args.emplace_back("-P0");
482 args.emplace_back("--protocol=SOCKET");
483 args.emplace_back("-S" + port_or_socket);
484 }
485 else
486
487 args.emplace_back("-P" + port_or_socket);
488
489#endif
490
491
492 args.emplace_back("--default-character-set=utf8");
493
494
495 args.emplace_back("--max-allowed-packet=1GB");
496
497#if !defined(MARIADB_VERSION_ID) && MYSQL_VERSION_ID >= 80000
498
499 if (ssl == "ssl")
500 args.emplace_back("--ssl-mode=REQUIRED");
501
502#else
503
504 if (ssl == "ssl")
505 args.emplace_back("--ssl");
506
507#endif
508
509
510 args.emplace_back("-e");
511 args.emplace_back(
Acore::StringFormat(
"BEGIN; SOURCE %s; COMMIT;", path.generic_string().c_str()));
512
513
514 if (!database.empty())
515 args.emplace_back(database);
516
517
519 "sql.updates", "", true);
520
521 if (ret != EXIT_SUCCESS)
522 {
523 LOG_FATAL(
"sql.updates",
"Applying of file \'{}\' to database \'{}\' failed!" \
524 " If you are a user, please pull the latest revision from the repository. "
525 "Also make sure you have not applied any of the databases with your sql client. "
526 "You cannot use auto-update system and import sql files from AzerothCore repository with your sql client. "
527 "If you are a developer, please fix your sql query.",
529
531 }
532}
#define sConfigMgr
Definition: Config.h:92
#define LOG_FATAL(filterType__,...)
Definition: Log.h:155
std::string StringFormat(Format &&fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:29
int StartProcess(std::string const &executable, std::vector< std::string > const &args, std::string const &logger, std::string input_file, bool secure)
Definition: StartProcess.cpp:146
AC_COMMON_API std::string AddSuffixIfNotExists(std::string str, const char suffix)
Util function to add a suffix char. Can be used to add a slash at the end of a path.
Definition: StringFormat.cpp:74
Definition: DBUpdater.h:38
static std::string GetCorrectedMySQLExecutable()
Definition: DBUpdater.cpp:32