OCT 增加一次查询获取所有结果的处理

This commit is contained in:
mengqingchao 2019-07-26 10:28:45 +08:00
parent 0c30a1f257
commit 5ec7a37bd9
1 changed files with 79 additions and 26 deletions

View File

@ -302,7 +302,7 @@ int update_database(int module_id, void * db_handle, int op_type, char * tabl
* table_name -
* sql_str - SQL语句
* begin_num -
* need_num -
* need_num - , need_num = 0
* param_num - 0SQL注入问题使
* Output:
*  return_num -
@ -341,7 +341,7 @@ void * select_datebase_by_number(int module_id, void * db_handle, char * table_
return NULL;
}
if ((begin_num <= 0) || (need_num <= 0))
if ((begin_num <= 0) || (need_num < 0))
{
return NULL;
}
@ -447,6 +447,12 @@ void * select_datebase_by_number(int module_id, void * db_handle, char * table_
}
json = cJSON_CreateObject();
if (NULL == json)
{
SQLCloseCursor(hstmt);
SQLFreeStmt(hstmt, SQL_DROP);
return NULL;
}
/* 将应用程序数据缓冲区绑定到结果集中的列 */
for (i = 1; i <= column_nmuber; i++)
@ -474,10 +480,16 @@ void * select_datebase_by_number(int module_id, void * db_handle, char * table_
/* 查询结果 */
FetchOrientation = SQL_FETCH_RELATIVE;
for (i = 1; i <= need_num; i++)
/* need_num为0表示一次返回所有找到的信息 */
if (0 == need_num)
{
while(1)
{
ret = SQLFetchScroll(hstmt, FetchOrientation, begin_num);
FetchOrientation = SQL_FETCH_NEXT;
/* 查找失败,表示已经返回所有找到的信息 */
if (ret != SQL_SUCCESS)
{
break;
@ -503,11 +515,52 @@ void * select_datebase_by_number(int module_id, void * db_handle, char * table_
}
else
{
/* 不支持类型,后续增加统计和打印 */
}
}
}
}
else
{
for (i = 1; i <= need_num; i++)
{
ret = SQLFetchScroll(hstmt, FetchOrientation, begin_num);
FetchOrientation = SQL_FETCH_NEXT;
/* 查找失败,表示已经返回所有找到的信息 */
if (ret != SQL_SUCCESS)
{
break;
}
ret_num++;
cJSON_AddItemToArray(array, obj = cJSON_CreateObject());
for (j = 1; j <= column_nmuber; j++)
{
if (SQL_BIGINT == db_column_info[j].dateType)
{
cJSON_AddNumberToObject(obj, db_column_info[j].name, *((long long *)&(value[j][0])));
}
else if (SQL_CHAR == db_column_info[j].dateType)
{
cJSON_AddStringToObject(obj, db_column_info[j].name , value[j][0]);
}
else if (SQL_DOUBLE == db_column_info[j].dateType)
{
cJSON_AddNumberToObject(obj, db_column_info[j].name , *((double *)&(value[j][0])));
}
else
{
/* 不支持类型,后续增加统计和打印 */
}
}
}
}
SQLCloseCursor(hstmt);
SQLFreeStmt(hstmt, SQL_DROP);