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-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;
|
|
|
|
|
};
|