Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SRC_INCLUDE_UTIL_MYSQLHELPER_H_
- #define SRC_INCLUDE_UTIL_MYSQLHELPER_H_
- #if!defined(EXPAND_MY_SSQLS_STATICS)
- #define MYSQLPP_SSQLS_NO_STATICS
- #endif
- #include <ssqls.h>
- sql_create_7(FaceTable, 1, 7, mysqlpp::sql_int, id, mysqlpp::sql_int, label,
- mysqlpp::sql_int, gender, mysqlpp::sql_double, genderconfidence,
- mysqlpp::sql_int, age, mysqlpp::sql_double, ageconfidence,
- mysqlpp::sql_datetime, date)
- using namespace std;
- mysqlpp::Connection connect();
- #define EXPAND_MY_SSQLS_STATICS
- #include "include/Util/MySQLHelper.h"
- mysqlpp::Connection connect() {
- const char *SERVER = "127.0.0.1";
- const char * USER = "root";
- const char * PASSWORD = "123456";
- const char *DB ="FaceDB";
- mysqlpp::Connection conn(false);
- if (conn.connect(DB, SERVER, USER, PASSWORD)) {
- return conn;
- }
- }
- #ifndef SRC_INCLUDE_DAO_FACEDAO_H_
- #define SRC_INCLUDE_DAO_FACEDAO_H_
- #include "include/Core/Face.h"
- #include <vector>
- #include <time.h>
- #include "include/DAO/FaceEntity.h"
- using namespace std;
- class FaceDAO {
- private:
- mysqlpp::Connection conn;
- public:
- FaceDAO();
- void insert(Face face, time_t time);
- };
- #endif /* SRC_INCLUDE_DAO_FACEDAO_H_ */
- #include "include/Util/MySQLHelper.h"
- #include "include/DAO/FaceDAO.h"
- FaceDAO::FaceDAO() {
- this->conn = connect();
- }
- void FaceDAO::insert(Face face, time_t datetime) {
- mysqlpp::sql_int id(0);
- mysqlpp::sql_int label(face.getLabel());
- mysqlpp::sql_int gender(face.getGender() == "male" ? 1 : 0);
- mysqlpp::sql_double genderconfidence(face.getGenderConfidence());
- mysqlpp::sql_int age(face.getAge());
- mysqlpp::sql_double ageconfidence(face.getAgeConfidence());
- mysqlpp::sql_datetime date(datetime);
- FaceTable entity(id, label, gender, genderconfidence, age, ageconfidence,
- date);
- mysqlpp::Query query = conn.query();
- try {
- query.insert(entity);
- query.execute();
- } catch (const mysqlpp::Exception &er) {
- cerr << "Error: " << er.what() << endl;
- exit(1);
- }
- }
- Invalid arguments ' Candidates are: mysqlpp::Query & insert(const #0 &) mysqlpp::Query & insert(#0, #0) '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement