UseDatabase.cpp 858 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "UseDatabase.h"
  2. #include "MySQLClient.h"
  3. #include <Logging.h>
  4. #include <StringAlgorithm.h>
  5. #include <sstream>
  6. #include <unistd.h>
  7. namespace Test {
  8. bool UseDatabase()
  9. {
  10. Logging::Log(Logging::Severity::Info, "UseDatabase");
  11. try
  12. {
  13. std::string hostname1 = "MySQL";
  14. std::string username1 = "datalog";
  15. std::string password1 = "NfhdUwjjdRbslR";
  16. std::string database1 = "datalog";
  17. MySQL::MySQLClient MySQLClient1;
  18. MySQLClient1.Connect(hostname1, username1, password1, database1);
  19. if (!MySQLClient1.Connected())
  20. return false;
  21. if (!StringAlgorithm::iequals(MySQLClient1.Database(), database1))
  22. return false;
  23. }
  24. catch (const std::exception& e)
  25. {
  26. std::stringstream ss;
  27. ss << "ERROR: " << e.what() << std::endl;
  28. Logging::Log(Logging::Severity::Error, ss.str());
  29. return false;
  30. }
  31. return true;
  32. }
  33. } // namespace Test