DbHelper.cc 740 B

123456789101112131415161718192021222324252627282930
  1. // Copyright: All Rights Reserved
  2. // Author: egametang@gmail.com (tanghai)
  3. #include <boost/format.hpp>
  4. #include "Orm/DbHelper.h"
  5. #include "Orm/Exception.h"
  6. namespace Egametang {
  7. DbHelper::DbHelper(std::string url, std::string username, std::string password)
  8. {
  9. try
  10. {
  11. sql::Driver* driver = get_driver_instance();
  12. connection.reset(driver->connect(url, username, password));
  13. }
  14. catch (sql::SQLException &e)
  15. {
  16. boost::format format("can't connect to %1%, username: %2%, password: %3%, error code: %4%");
  17. format % url % username % password % e.getErrorCode();
  18. throw ConnectionException() << ConnectionErrStr(format.str());
  19. }
  20. statement.reset(connection->createStatement());
  21. }
  22. DbHelper::~DbHelper()
  23. {
  24. }
  25. } // namespace Egametang