Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #ifndef SRC_INCLUDE_UTIL_MYSQLHELPER_H_
  2. #define SRC_INCLUDE_UTIL_MYSQLHELPER_H_
  3.  
  4. #if!defined(EXPAND_MY_SSQLS_STATICS)
  5. #define MYSQLPP_SSQLS_NO_STATICS
  6. #endif
  7. #include <ssqls.h>
  8. sql_create_7(FaceTable, 1, 7, mysqlpp::sql_int, id, mysqlpp::sql_int, label,
  9. mysqlpp::sql_int, gender, mysqlpp::sql_double, genderconfidence,
  10. mysqlpp::sql_int, age, mysqlpp::sql_double, ageconfidence,
  11. mysqlpp::sql_datetime, date)
  12.  
  13. using namespace std;
  14. mysqlpp::Connection connect();
  15.  
  16. #define EXPAND_MY_SSQLS_STATICS
  17. #include "include/Util/MySQLHelper.h"
  18.  
  19. mysqlpp::Connection connect() {
  20. const char *SERVER = "127.0.0.1";
  21. const char * USER = "root";
  22. const char * PASSWORD = "123456";
  23. const char *DB ="FaceDB";
  24. mysqlpp::Connection conn(false);
  25. if (conn.connect(DB, SERVER, USER, PASSWORD)) {
  26. return conn;
  27. }
  28. }
  29.  
  30. #ifndef SRC_INCLUDE_DAO_FACEDAO_H_
  31. #define SRC_INCLUDE_DAO_FACEDAO_H_
  32.  
  33. #include "include/Core/Face.h"
  34. #include <vector>
  35. #include <time.h>
  36. #include "include/DAO/FaceEntity.h"
  37. using namespace std;
  38. class FaceDAO {
  39. private:
  40. mysqlpp::Connection conn;
  41. public:
  42. FaceDAO();
  43. void insert(Face face, time_t time);
  44. };
  45.  
  46. #endif /* SRC_INCLUDE_DAO_FACEDAO_H_ */
  47.  
  48. #include "include/Util/MySQLHelper.h"
  49. #include "include/DAO/FaceDAO.h"
  50. FaceDAO::FaceDAO() {
  51. this->conn = connect();
  52. }
  53. void FaceDAO::insert(Face face, time_t datetime) {
  54. mysqlpp::sql_int id(0);
  55. mysqlpp::sql_int label(face.getLabel());
  56. mysqlpp::sql_int gender(face.getGender() == "male" ? 1 : 0);
  57. mysqlpp::sql_double genderconfidence(face.getGenderConfidence());
  58. mysqlpp::sql_int age(face.getAge());
  59. mysqlpp::sql_double ageconfidence(face.getAgeConfidence());
  60. mysqlpp::sql_datetime date(datetime);
  61. FaceTable entity(id, label, gender, genderconfidence, age, ageconfidence,
  62. date);
  63. mysqlpp::Query query = conn.query();
  64. try {
  65. query.insert(entity);
  66. query.execute();
  67. } catch (const mysqlpp::Exception &er) {
  68. cerr << "Error: " << er.what() << endl;
  69. exit(1);
  70. }
  71. }
  72.  
  73. Invalid arguments ' Candidates are: mysqlpp::Query & insert(const #0 &) mysqlpp::Query & insert(#0, #0) '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement