SingleConnection.cpp 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "SingleConnection.h"
  2. #include "MySQLClient.h"
  3. #include <Logging.h>
  4. #include <sstream>
  5. namespace Test {
  6. bool SingleConnection()
  7. {
  8. Logging::Log(Logging::Severity::Info, "SingleConnection");
  9. try
  10. {
  11. std::string hostname1 = "MySQL";
  12. std::string username1 = "datalog";
  13. std::string password1 = "NfhdUwjjdRbslR";
  14. std::string database1 = "datalog";
  15. MySQL::MySQLClient MySQLClient1;
  16. MySQLClient1.Connect(hostname1, username1, password1, database1);
  17. if (!MySQLClient1.Connected())
  18. return false;
  19. std::stringstream query1;
  20. query1 << "SELECT * FROM `datalog` LIMIT 1;";
  21. auto result1 = MySQLClient1.ExecuteQuery(query1.str());
  22. if (result1.RowsCount() == 0)
  23. return false;
  24. result1.First();
  25. auto id1 = result1.Int("device_id");
  26. if (id1 == 0)
  27. return false;
  28. }
  29. catch (const std::exception& e)
  30. {
  31. std::stringstream ss;
  32. ss << "ERROR: " << e.what() << std::endl;
  33. Logging::Log(Logging::Severity::Error, ss.str());
  34. return false;
  35. }
  36. return true;
  37. }
  38. } // namespace Test