#ifndef _DbMysql_H_
#define _DbMysql_H_

#pragma warning(disable:4100)

#include <sstream>
#include <memory>
#include <iostream>
#include <functional>
#include <string>
#include <map>
#include <vector>
#include "mysql.h"
#include "Fields.h"

using namespace std;

struct MysqlOption
{
	std::string host;
	std::string user;
	std::string password;
	std::string dbname;
	int port;
};

class MysqlClient
{
public:
	MysqlClient(MysqlOption option);
	~MysqlClient();

	/**
	* @brief: 连接MYSQL数据库
	* return: [int]
	*/
	int conn();

	/**
	* @brief 是否成功连接数据库
	* @return true:连接成功；false:未连接或连接失败
	*/
	bool isConnected();

	/**
	* @brief: 关闭数据库连接
	*/
	void close();

	/**
	* @brief: 执行sql语句
	*/
	int exec(std::string sql);

	/**
	* @brief: 执行sql语句, 获取查询结果集
	*/
	int exec(std::string, vector<Fields>& result);

private:
	// mysql数据库连接对象
	MYSQL* mysql_ = nullptr;

	// 数据库连接信息
	MysqlOption option;
};

#endif // !!! _DbMysql_H_
