DbHelper.h 903 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright: All Rights Reserved
  2. // Author: egametang@gmail.com (tanghai)
  3. #ifndef ORM_SQLHELPER_H
  4. #define ORM_SQLHELPER_H
  5. #include <boost/scoped_ptr.hpp>
  6. #include <cppconn/driver.h>
  7. #include <cppconn/exception.h>
  8. #include <cppconn/resultset.h>
  9. #include <cppconn/statement.h>
  10. #include <mysql_connection.h>
  11. #include "Orm/DbResult.h"
  12. #include "Orm/OrmTypedef.h"
  13. #include "Orm/Select.h"
  14. namespace Egametang {
  15. class DbHelper
  16. {
  17. private:
  18. boost::scoped_ptr<sql::Connection> connection;
  19. boost::scoped_ptr<sql::Statement> statement;
  20. public:
  21. DbHelper(std::string url, std::string username, std::string password);
  22. virtual ~DbHelper();
  23. template <typename Table>
  24. DbResultPtr Execute(Select<Table> select)
  25. {
  26. ResultSetPtr resultSet(statement->executeQuery(select.ToString()));
  27. DbResultPtr dbResult(new DbResult(resultSet));
  28. return dbResult;
  29. }
  30. };
  31. } // namespace Egametang
  32. #endif // ORM_SQLHELPER_H