// NB: I would like to know if this is the correct way to do this in terms of calloc() and free()
// C functions to read data from a MYSQL row
// Usage:
// char** result_arr;
// db_gets_all(result, row, &result_arr, 4);
// printf("%s", result_arr[0]);
// db_gets_all_free(&result_arr, 4);
void db_gets_all(MYSQL_RES* result, MYSQL_ROW row, char*** result_arr, size_t nrows)
{
int i;
char** arr_local;
if( (arr_local = calloc(nrows, sizeof *arr_local)) != NULL )
{
for(i = 0;i < nrows;i++)
{
arr_local[i] = db_gets(result, row, i);
}
}
*result_arr = arr_local;
}
void db_gets_all_free(char*** result_arr, size_t nrows)
{
int i;
for(i = 0;i < nrows;i++) free_tmp((*result_arr)[i], "db_gets_all_free");
free_tmp(*result_arr, "db_gets_all_free");
}