-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.h
71 lines (67 loc) · 2.49 KB
/
database.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*************************************************************************
# > File Name: database.h
# > Author: SSZL
# > Mail: sszllzss@foxmail.com
# > Blog: sszlbg.cn
# > Created Time: 2018-10-01 21:32:50
# > Revise Time: 2018-10-16 19:43:19
************************************************************************/
#ifndef _DATABASE_H
#define _DATABASE_H
// 编译请加 -std=c++11 选项
#include <mysql/mysql.h>
#include "CMutex.hpp"
#include "mysql_db.hpp"
class DataBase : private CMutex
{
private:
MysqlDB *mysqlDB;
DataBase();
~DataBase();
public:
static DataBase &getInstance();
int AddUser(std::string user, std::string pwd, std::string nikename, std::string Email = "", int role = 1);
int CheckUpUser(std::string user);
int ReviseUserPwd(std::string user, std::string pwd,std::string newPwd);
int ReviseUserRole(std::string user, int role);
int ReviseUserNikename(std::string, std::string nikename);
int ReviseUserEmail(std::string user, std::string Email);
int UserLogin(std::string user,std::string pwd);
int AddSensor(std::string user, std::string sensorID,std::string key);
std::string CheckUpSensor(std::string sensorID);
Mysql_strList * GetUserSensorList(std::string user);
int DelSensor(std::string user, std::string sensorID);
int DelSensor(std::string sensorID);
int CheckUpSensorIsUser(std::string user, std::string sensorID);
int ReviseSensor(std::string user, std::string sensorID, std::string newKey);
int ReviseSensor(std::string sensorID, std::string newKey);
int AddSensorData(std::string sensorID, std::string date, double illumination, double humidity, double temperature);
Mysql_Res * GetSensorRes(std::string sensorID,std::string startDate, std::string endDate);
Mysql_Res * GetUserAllSensorRes(std::string user,std::string startDate, std::string endDate);
int DelSensorAllData(std::string sensorID);
int DelSensorAllData(std::string user, std::string sensorID);
//懒汉 线程安全 自动回收
//private:
/* static DataBase * instance; */
/* static CMutex instance_lock; */
/*
class GC // 垃圾回收类
{
public:
GC(){
}
~GC()
{
if (instance != NULL)
{
delete instance;
instance = NULL;
}
}
};
static GC gc; //垃圾回收类的静态成员
*/
//public:
/* static DataBase *getInstance(); */
};
#endif