acl/lib_acl_cpp/include/acl_cpp/hsocket/hsclient.hpp

206 lines
6.9 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <map>
#include <vector>
2017-06-02 14:47:24 +08:00
#include "../stdlib/string.hpp"
#include "../stdlib/noncopyable.hpp"
2017-06-02 14:47:24 +08:00
#include "../stream/socket_stream.hpp"
#include "../hsocket/hsproto.hpp"
2014-11-19 00:25:21 +08:00
#ifndef ACL_CLIENT_ONLY
2014-11-19 00:25:21 +08:00
struct ACL_ARGV;
namespace acl {
class hsrow;
class hstable;
class ACL_CPP_API hsclient : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
/**
*
* @param addr {const char*} handlersocket Mysql
* @param cache_enable {bool}
* @param retry_enable {bool}
* ip:port
2014-11-19 00:25:21 +08:00
*/
hsclient(const char* addr, bool cache_enable = true, bool retry_enable = true);
~hsclient();
/**
*
* @param values {const char*[]} open
* flds
* @param num {int} values flds
*
* @param cond {const char*}
* = ; >= ; > ; < ; <=
* @param nlimit {int} 0
* @param noffset {int} (0)
* @return {const std::verctor<hsrow*>&}
2014-11-19 00:25:21 +08:00
*/
const std::vector<hsrow*>& get(const char* values[], int num,
const char* cond = "=", int nlimit = 0, int noffset = 0);
/**
*
* @param first_value {const char*} flds
*
* @param ... {const char*} NULL
* @return {const std::verctor<hsrow*>&}
2014-11-19 00:25:21 +08:00
*/
const std::vector<hsrow*>& get(const char* first_value, ...)
ACL_CPP_PRINTF(2, 3);
/**
*
* @param values {const char*[]} open
* flds
* @param num {int} values flds
*
* @param to_values {cosnt *[]} open
*
* @param to_num {int} to_values
* @param cond {const char*}
* = ; >= ; > ; < ; <=
* @param nlimit {int} 0
* @param noffset {int} (0)
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool mod(const char* values[], int num,
const char* to_values[], int to_num,
const char* cond = "=", int nlimit = 0, int noffset = 0);
/**
*
* @param values {const char*[]} open
* flds
* @param num {int} values flds
*
* @param cond {const char*}
* = ; >= ; > ; < ; <=
* @param nlimit {int} , 0
* @param noffset {int} (0)
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool del(const char* values[], int num, const char* cond = "=",
int nlimit = 0, int noffset = 0);
/**
*
* @param first_value {const char*} flds
*
* @param ... {const char*} NULL
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool fmt_del(const char* first_value, ...) ACL_CPP_PRINTF(2, 3);
/**
*
* @param values {const char*[]}
* flds
* @param num {int} values flds
*
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool add(const char* values[], int num);
/**
*
* @param first_value {const char*} flds
*
* @param ... {const char*} NULL
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool fmt_add(const char* first_value, ...) ACL_CPP_PRINTF(2, 3);
/**
*
* @param on {bool} true
2014-11-19 00:25:21 +08:00
*/
void debug_enable(bool on);
/**
*
* @param dbn {const char*}
* @param tbl {const char*}
* @param idx {const char*}
* @param flds {const char*}
* ",; \t" user_id,user_name,user_mail
* @param auto_open {bool}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool open_tbl(const char* dbn, const char* tbl,
const char* idx, const char* flds, bool auto_open = true);
/**
*
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
const char* get_addr() const;
/**
*
2014-11-19 00:25:21 +08:00
* @return {int}
*/
int get_error() const;
/**
*
* @param errnum {int} get_error
2014-11-19 00:25:21 +08:00
* @return {const char*}
*/
const char* get_serror(int errnum) const;
/**
*
2014-11-19 00:25:21 +08:00
* @return {const char*}
*/
const char* get_last_serror() const;
/**
* hsclient id
2014-11-19 00:25:21 +08:00
* @return {int}
*/
int get_id() const;
private:
bool debugOn_;
char* addr_;
hsproto proto_;
bool retry_enable_;
int id_max_;
hstable* tbl_curr_;
string buf_;
// 服务器连接流
2014-11-19 00:25:21 +08:00
socket_stream stream_;
std::map<string, hstable*> tables_;
char cond_def_[2];
int error_;
const char* serror_;
// 打开数据库连接
2014-11-19 00:25:21 +08:00
bool open_tbl(const char* dbn, const char* tbl,
const char* idx, const char* flds, const char* key);
// 当读写数据库连接流出错时需要调用此函数来关闭连接流及释放
// 表对象
2014-11-19 00:25:21 +08:00
void close_stream();
// 清理内部打开的数据库表的对象
2014-11-19 00:25:21 +08:00
void clear_tables();
// 向数据库发送查询命令并取得结果数据
2014-11-19 00:25:21 +08:00
bool query(const char* oper, const char* values[], int num,
const char* limit_offset, char mop,
const char* to_values[], int to_num);
bool chat();
};
} // namespace acl
#endif // ACL_CLIENT_ONLY