MySQLWrapper/MySQLWrapper.h
2017-08-07 00:09:43 +08:00

50 lines
992 B
C++

#pragma once
#include <functional>
#include <string>
class MySQLResult
{
public:
MySQLResult();
~MySQLResult();
/// 获取数据表的表头数量和结果行数
unsigned int getNumFields();
uint64_t getNumRows();
/// 获取数据表的表头名称
char* getFieldName(int Index);
/// 对于每行数据执行func
void stepRow(const std::function<void(char** RowPtr,unsigned long* FieldLength)>& func);
private:
struct impl;
impl* pimpl;
friend class MySQLConn;
};
class MySQLConn
{
public:
MySQLConn();
~MySQLConn();
/// 数据库连接
int connect(const char* host,const char* user,const char* passwd,const char* db,unsigned int port);
/// 执行SQL语句
int exec(const std::string& SQLCommand,const std::function<void(MySQLResult&)>& res);
/// 获取错误信息
const char* getError();
/// 当结果为空时用于判断数据库运行正常与否
unsigned int getFieldCount();
uint64_t getAffectedRows();
private:
struct impl;
impl* pimpl;
};