-
Notifications
You must be signed in to change notification settings - Fork 18
/
mydatabase.h
49 lines (43 loc) · 1.48 KB
/
mydatabase.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
#ifndef MYDATABASE_H
#define MYDATABASE_H
#include <QTextCodec>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QTime>
#include <QSqlError>
#include <QDebug>
#include <QSqlDriver>
#include <QSqlRecord>
#include <QDir>
class MyDataBase
{
public:
MyDataBase() = delete;
MyDataBase(QString HostName, QString DatabaseName); //QSQLITE不需要用户名与密码
MyDataBase(QString HostName, QString DatabaseName, QString UserNmae, QString Password);
~MyDataBase();
public:
//创建表
bool create_table(QString table_name,QMap<QString,QString> table_data); //函数模板
//发送数据库语句
bool db_query(QString m_query_sql);
bool add(QString table_name,QMap<QString,QString> data); //增加数据
bool del(QString table_name,QMap<QString,QString> where); //删除一条记录
bool updata(QString table_name,QMap<QString,QString> where,QMap<QString,QString> data); //更新数据
bool find(QString table_name,QList<QString> key,QMap<QString,QString> where,QList<QList<QString>> *row); //查找
bool find(QString table_name,QList<QString> key,QList<QList<QString>> *row); //查找所有
// 判断表格是否存在
bool IsExist(QString tableName);
QString getError();
public:
QSqlDatabase m_db;
private:
QString m_HostName;
QString m_DatabaseName;
QString m_UserNmae;
QString m_Password;
QSqlError m_error;
QSqlRecord m_rec;
QSqlQuery * m_query;
};
#endif // MYDATABASE_H