52 lines
1.2 KiB
C++
52 lines
1.2 KiB
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();
|
|
|
|
/// 数据库连接
|
|
/// 返回值: 0:连接正常, -1:连接错误
|
|
int connect(const char* host,const char* user,const char* passwd,const char* db,unsigned int port);
|
|
|
|
/// 执行SQL语句
|
|
/// 返回值: 1: 语句执行正常,无返回结果(func未执行) 0:语句执行正常,返回结果集交付func执行. -1:语句执行错误.(mysql_real_query失败) -2: 语句执行正确,获取结果出现错误
|
|
int exec(const std::string& SQLCommand,const std::function<void(MySQLResult&)>& func);
|
|
|
|
/// 获取错误信息
|
|
const std::string& getError();
|
|
|
|
/// 当结果为空时用于判断数据库运行正常与否
|
|
unsigned int getFieldCount();
|
|
uint64_t getAffectedRows();
|
|
private:
|
|
struct impl;
|
|
impl* pimpl;
|
|
};
|