MySQLWrapper/MySQLWrapper.h

60 lines
1.3 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();
2017-11-19 15:32:27 +08:00
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2017-08-07 00:09:43 +08:00
unsigned int getNumFields();
2017-11-19 15:32:27 +08:00
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2017-08-07 00:09:43 +08:00
uint64_t getNumRows();
2017-11-19 15:32:27 +08:00
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2017-08-07 00:09:43 +08:00
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-11-14 14:43:25 +08:00
int connect(const std::string& host, const std::string& user, const std::string& passwd, const std::string& db, unsigned int port);
2017-08-07 00:09:43 +08:00
/// ִ<><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-11-14 14:43:25 +08:00
unsigned int getErrCode();
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();
2017-11-14 14:43:25 +08:00
protected:
/// <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD>Ϣ
void _doUpdateError();
2017-08-07 00:09:43 +08:00
private:
struct impl;
impl* pimpl;
};