/**
* @brief
数据库公共头文件

* @version
V 1.0.0

* @author
王益俊

* @date
创建时间:  2018-04-19\n

* @note
2018-04-19  初次创建。\n

* @warning

* @bug

*/

#ifndef DB_COMMON_H
#define DB_COMMON_H

#include <mysql.h>

namespace YADB
{
    //----------------------------------------------------------------------------
	//                                 数据库错误定义
	//----------------------------------------------------------------------------
	const int DB_ERR_NO_ERROR               = 0;//无错误
	const int DB_ERR_NOT_CONNECT_DB         = -1;//未连接数据库
	const int DB_ERR_EXCUTE_QUERY           = -1;//执行查询失败
	const int DB_ERR_QUERY_RES_NOT_INITED   = -1;//查询结果集还未初始化

	//----------------------------------------------------------------------------
	//                                 其它定义
	//----------------------------------------------------------------------------
	const int MAX_ASYNC_EXEC_FAILED_COUNT   = 3;//最大异步执行失败次数
	const int MAX_ASYNC_QUEQUE_CAPACITY     = 32 * 1024;//异步执行队列最大容量

	/**
	* @brief
	数据库连接数枚举
	*/
	enum _DB_CONNECT_COUNT_
	{
		DCC_MIN_COUNT = 1,//最小连接数
		DCC_MAX_COUNT = 60,//最大连接数
	};

	/**
	* @brief
	数据库连接设置结构体
	*/
    struct _DB_CONN_SETTING_
	{
		unsigned int Port;//端口
		int TimeOut;//连接数据库超时(单位:秒)
		std::string Host;//数据库主机地址
		std::string User;//用户名
		std::string PWD;//密码
		std::string DBName;//数据库名
		std::string CharSet;//字符集
		std::string stmtSQL;//预处理SQL
		_DB_CONN_SETTING_()
		{
			Port    = 3306;
			TimeOut = 0;
		}
	};

	/**
	* @brief
	数据库连接池设置结构体
	*/
	struct _DB_POOL_SETTING_ : public _DB_CONN_SETTING_
	{
		int PoolSize;//连接池大小
		_DB_POOL_SETTING_()
		{
			PoolSize = 0;
		}
	};

    /**
    * @brief
    异步执行结构体
    */
	struct _ASYNC_SQL_
	{
		int FailedCount;//执行失败次数
		std::string SQL; //SQ语句
		_ASYNC_SQL_()
		{
			FailedCount = 0;
		}
		~_ASYNC_SQL_()
		{

		}
	};
}

#endif