/* * Convert rows from internal to db API representation */ static int dbt_convert_rows(db1_res_t* _r, dbt_result_p _dres) { int row; dbt_row_p _rp = NULL; if (!_r || !_dres) { LM_ERR("invalid parameter\n"); return -1; } RES_ROW_N(_r) = _dres->nrrows; if (!RES_ROW_N(_r)) { return 0; } if (db_allocate_rows(_r) < 0) { LM_ERR("could not allocate rows"); return -2; } row = 0; _rp = _dres->rows; while(_rp) { if (dbt_convert_row(_r, &(RES_ROWS(_r)[row]), _rp) < 0) { LM_ERR("failed to convert row #%d\n", row); RES_ROW_N(_r) = row; db_free_rows(_r); return -4; } row++; _rp = _rp->next; } return 0; }
/* * Convert rows from internal to db API representation */ int dbt_convert_rows(db_con_t* _h, db_res_t* _r) { int n, i; dbt_row_p _rp = NULL; if ((!_h) || (!_r)) { #ifdef DBT_EXTRA_DEBUG LOG(L_ERR, "DBT:dbt_convert_rows: Invalid parameter\n"); #endif return -1; } n = DBT_CON_RESULT(_h)->nrrows; RES_ROW_N(_r) = n; if (!n) { RES_ROWS(_r) = 0; return 0; } RES_ROWS(_r) = (struct db_row*)pkg_malloc(sizeof(db_row_t) * n); if (!RES_ROWS(_r)) { LOG(L_ERR, "DBT:dbt_convert_rows: No memory left\n"); return -2; } i = 0; _rp = DBT_CON_RESULT(_h)->rows; while(_rp) { DBT_CON_ROW(_h) = _rp; if (!DBT_CON_ROW(_h)) { LOG(L_ERR, "DBT:dbt_convert_rows: error getting current row\n"); RES_ROW_N(_r) = i; dbt_free_rows(_r); return -3; } if (dbt_convert_row(_h, _r, &(RES_ROWS(_r)[i])) < 0) { LOG(L_ERR, "DBT:dbt_convert_rows: Error while converting" " row #%d\n", i); RES_ROW_N(_r) = i; dbt_free_rows(_r); return -4; } i++; _rp = _rp->next; } return 0; }
/* * Convert rows from internal to db API representation */ static int dbt_convert_rows(db_con_t* _h, db_res_t* _r) { int col; dbt_row_p _rp = NULL; if (!_h || !_r) { LM_ERR("invalid parameter\n"); return -1; } RES_ROW_N(_r) = DBT_CON_RESULT(_h)->nrrows; if (!RES_ROW_N(_r)) { return 0; } if (db_allocate_rows( _r, RES_ROW_N(_r))!=0) { LM_ERR("no private memory left\n"); return -2; } col = 0; _rp = DBT_CON_RESULT(_h)->rows; while(_rp) { DBT_CON_ROW(_h) = _rp; if (!DBT_CON_ROW(_h)) { LM_ERR("failed to get current row\n"); RES_ROW_N(_r) = col; db_free_rows(_r); return -3; } if (dbt_convert_row(_h, _r, &(RES_ROWS(_r)[col])) < 0) { LM_ERR("failed to convert row #%d\n", col); RES_ROW_N(_r) = col; db_free_rows(_r); return -4; } col++; _rp = _rp->next; } return 0; }