예제 #1
0
/*
 * Free all memory allocated by get_result
 */
int dbt_free_query(db_con_t* _h, db_res_t* _r)
{
	if ((!_h) || (!_r))
	{
#ifdef DBT_EXTRA_DEBUG
		LOG(L_ERR, "DBT:dbt_free_query: Invalid parameter value\n");
#endif
		return -1;
	}

	if(dbt_free_result(_r) < 0) 
	{
		LOG(L_ERR,"DBT:dbt_free_query:Unable to free result structure\n");
		return -1;
	}

	
	if(dbt_result_free(DBT_CON_RESULT(_h)) < 0) 
	{
		LOG(L_ERR, "DBT:dbt_free_query: Unable to free internal structure\n");
		return -1;
	}
	DBT_CON_RESULT(_h) = NULL;
	return 0;
}
예제 #2
0
int dbt_fetch_result(db1_con_t* _h, db1_res_t** _r, const int nrows)
{
	int rows;

	if (!_h || !_r || nrows < 0) {
		LM_ERR("Invalid parameter value\n");
		return -1;
	}

	/* exit if the fetch count is zero */
	if (nrows == 0) {
		dbt_free_result(_h, *_r);
		*_r = 0;
		return 0;
	}

	if(*_r==0) {
		/* Allocate a new result structure */
		dbt_init_result(_r, last_temp_table);
	} else {
		/* free old rows */
		if(RES_ROWS(*_r)!=0)
			db_free_rows(*_r);
		RES_ROWS(*_r) = 0;
		RES_ROW_N(*_r) = 0;
	}

	/* determine the number of rows remaining to be processed */
	rows = RES_NUM_ROWS(*_r) - RES_LAST_ROW(*_r);

	/* If there aren't any more rows left to process, exit */
	if(rows<=0)
		return 0;

	/* if the fetch count is less than the remaining rows to process                 */
	/* set the number of rows to process (during this call) equal to the fetch count */
	if(nrows < rows)
		rows = nrows;
	
	RES_ROW_N(*_r) = rows;

	return dbt_get_next_result(_r, RES_LAST_ROW(*_r), rows);
}