MySQLWrapper/MySQLWrapper.h

52 lines
1.2 KiB
C
Raw Normal View History

2017-08-07 00:09:43 +08:00
#pragma once
#include <functional>
#include <string>
class MySQLResult
{
public:
MySQLResult();
~MySQLResult();
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݱ<EFBFBD><DDB1>ı<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned int getNumFields();
uint64_t getNumRows();
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݱ<EFBFBD><DDB1>ı<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
char* getFieldName(int Index);
/// <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>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();
/// <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
2017-08-07 10:55:28 +08:00
/// <20><><EFBFBD><EFBFBD>ֵ: 0:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, -1:<3A><><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD>
2017-08-07 00:09:43 +08:00
int connect(const char* host,const char* user,const char* passwd,const char* db,unsigned int port);
/// ִ<><D6B4>SQL<51><4C><EFBFBD><EFBFBD>
2017-08-07 10:55:28 +08:00
/// <20><><EFBFBD><EFBFBD>ֵ: 1: <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>޷<EFBFBD><DEB7>ؽ<EFBFBD><D8BD><EFBFBD>(funcδִ<CEB4><D6B4>) 0:<3A><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>funcִ<63><D6B4>. -1:<3A><><EFBFBD><EFBFBD>ִ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>.(mysql_real_queryʧ<79><CAA7>) -2: <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD>ȷ,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>
int exec(const std::string& SQLCommand,const std::function<void(MySQLResult&)>& func);
2017-08-07 00:09:43 +08:00
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
2017-08-07 10:55:28 +08:00
const std::string& getError();
2017-08-07 00:09:43 +08:00
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned int getFieldCount();
uint64_t getAffectedRows();
private:
struct impl;
impl* pimpl;
};