| 3257 | } |
| 3258 | |
| 3259 | int cbm_store_coverage_get(cbm_store_t *s, const char *project, cbm_coverage_row_t **out, |
| 3260 | int *count) { |
| 3261 | *out = NULL; |
| 3262 | *count = 0; |
| 3263 | if (!s || !s->db || !project) { |
| 3264 | return CBM_STORE_ERR; |
| 3265 | } |
| 3266 | sqlite3_stmt *stmt = NULL; |
| 3267 | if (sqlite3_prepare_v2(s->db, |
| 3268 | "SELECT rel_path, kind, detail FROM index_coverage " |
| 3269 | "WHERE project = ?1 ORDER BY rel_path, kind;", |
| 3270 | CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 3271 | store_set_error_sqlite(s, "coverage get prepare"); |
| 3272 | return CBM_STORE_ERR; |
| 3273 | } |
| 3274 | bind_text(stmt, SKIP_ONE, project); |
| 3275 | int cap = ST_INIT_CAP_16; |
| 3276 | int n = 0; |
| 3277 | cbm_coverage_row_t *arr = malloc(cap * sizeof(cbm_coverage_row_t)); |
| 3278 | int scan_rc6; |
| 3279 | while ((scan_rc6 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 3280 | if (n >= cap) { |
| 3281 | cap *= ST_GROWTH; |
| 3282 | arr = safe_realloc(arr, cap * sizeof(cbm_coverage_row_t)); |
| 3283 | } |
| 3284 | arr[n].rel_path = heap_strdup((const char *)sqlite3_column_text(stmt, 0)); |
| 3285 | arr[n].kind = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE)); |
| 3286 | arr[n].detail = heap_strdup((const char *)sqlite3_column_text(stmt, CBM_SZ_2)); |
| 3287 | n++; |
| 3288 | } |
| 3289 | if (scan_rc6 != SQLITE_DONE) { /* SCANCHK:6:stmt */ |
| 3290 | store_set_error_sqlite(s, "row scan aborted"); |
| 3291 | sqlite3_finalize(stmt); |
| 3292 | cbm_store_free_coverage(arr, n); |
| 3293 | *out = NULL; |
| 3294 | *count = 0; |
| 3295 | return CBM_STORE_ERR; |
| 3296 | } |
| 3297 | sqlite3_finalize(stmt); |
| 3298 | *out = arr; |
| 3299 | *count = n; |
| 3300 | return CBM_STORE_OK; |
| 3301 | } |
| 3302 | |
| 3303 | void cbm_store_free_coverage(cbm_coverage_row_t *rows, int count) { |
| 3304 | if (!rows) { |
no test coverage detected