secgateway/Platform/common/database/database.h

162 lines
6.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef DB_H
#define DB_H
/* 返回值 */
#define DB_RET_OK 0
#define DB_RET_ERR 1
#define DB_RET_PARAM_NULL 2
#define DB_RET_PARAM_ERR 3
/* 数据库操作类型 */
#define DB_OP_INSERT 1
#define DB_OP_DEL 2
#define DB_OP_UPDATE 3
/* 数据库支持的参数类型 */
#define DB_DATA_INT_TYPE 1
#define DB_DATA_STRING_TYPE 2
#define DB_DATA_FLOAT_TYPE 3
#endif
/* 模块ID */
enum
{
DB_MODULE_ID_INVALID = 0,
DB_MODULE_ID_MAX,
};
/* 数据库TABLE属性 */
#define DB_ROWS 20 /* 支持的最大列数 */
#define DB_COLUMN 1 /* 单次查询获取的条目数 */
#define DB_ROWS_MAX_LEN 99 /* 列支持的最大长度。单位:字节 */
/*********************************************************************************
  * Description  
* 连接数据库操作
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
  * Output:
* 
  * Return:
* 数据库句柄
* NULL - 连接数据库失败
* 非NULL - 连接数据库成功
  * Others:
* 无
**********************************************************************************/
void * connect_database (int module_id);
/*********************************************************************************
  * Description  
* 释放数据库连接
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
  * db_handle - 数据库句柄
* Output:
* 
  * Return:
* DB_RET_PARAM_NULL - 入参指针为NULL
* DB_RET_ERR - 释放失败
* DB_RET_OK - 释放成功
  * Others:
* 无
**********************************************************************************/
int disconnect_database (int module_id, void * db_handle);
/*********************************************************************************
  * Description  
* 创建数据库表
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
  * db_handle - 数据库句柄
* table_name - 创建的表名
* sql_str - 创建表的SQL语句
* Output:
* 
  * Return:
* DB_RET_PARAM_NULL - 入参指针为NULL
* DB_RET_PARAM_NULL - 入参指针为NULL
* DB_RET_ERR - 释放失败
* DB_RET_OK - 释放成功
  * Others:
* 无
**********************************************************************************/
int create_database_table(int module_id, void * db_handle, char * table_name, char * sql_str);
/*********************************************************************************
  * Description  
* 对据库表执行插入、删除、更新操作
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
  * db_handle - 数据库句柄
* op_type - 操作类型 DB_OP_INSERT插入数据 DB_OP_DEL删除数据 DB_OP_UPDATE更新数据
* table_name - 创建的表名
* sql_str - 创建表的SQL语句
* param_num - 扩展参数组合数量填写0表示没有需要防止SQL注入问题需要使用扩展参数组合
* Output:
* 
  * Return:
* DB_RET_PARAM_NULL - 入参指针为NULL
* DB_RET_ERR - 操作失败
* DB_RET_OK - 操作成功
  * Others:
* 无
**********************************************************************************/
int update_database(int module_id, void * db_handle, int op_type, char * table_name, char * sql_str, int param_num, ...);
/*********************************************************************************
  * Description  
* 根据指定信息查找数据库
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
  * db_handle - 数据库句柄
* table_name - 创建的表名
* sql_str - 创建表的SQL语句
* begin_num - 从第几条查询结果开始返回
* need_num - 应用需要返回的结果条数
* param_num - 扩展参数组合数量填写0表示没有需要防止SQL注入问题需要使用扩展参数组合
* Output:
*  return_num - 实际返回的结果条数
  * Return:
* NULL - 操作失败
* 非NULL - 返回CJSON格式的查询结果
  * Others:
* 无
**********************************************************************************/
void * select_datebase_by_number(int module_id, void * db_handle, char * table_name, char * sql_str, int begin_num, int need_num, int * return_num, int param_num, ...);
/*********************************************************************************
  * Description  
* 释放查询接口申请的内存
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
* table_name - 创建的表名
* memory_ptr - 待释放内存指针
* Output:
* 
  * Return:
* DB_RET_PARAM_NULL - 入参指针为NULL
* DB_RET_ERR - 操作失败
* DB_RET_OK - 操作成功
  * Others:
* 无
**********************************************************************************/
int free_database_memory(int module_id, char * table_name, void * memory_ptr);
/*********************************************************************************
  * Description  
* 返回根据指定信息查找数据库的结果的条目数
  * Input:  
* module_id - 模块ID每个模块需要向数据库模块设置模块ID用于打印、统计使用
  * db_handle - 数据库句柄
* table_name - 创建的表名
* sql_str - 创建表的SQL语句
* param_num - 扩展参数组合数量填写0表示没有需要防止SQL注入问题需要使用扩展参数组合
* Output:
*  ret_num - 实际返回的结果条数
  * Return:
* DB_RET_PARAM_NULL - 入参指针为NULL
* DB_RET_ERR - 操作失败
* DB_RET_OK - 操作成功
  * Others:
* 无
**********************************************************************************/
int get_select_datebase_number(int module_id, void * db_handle, char * table_name, char * sql_str, int * ret_num, int param_num, ...);