| 3147 | } |
| 3148 | |
| 3149 | int cbm_store_coverage_get(cbm_store_t *s, const char *project, cbm_coverage_row_t **out, |
| 3150 | int *count) { |
| 3151 | *out = NULL; |
| 3152 | *count = 0; |
| 3153 | if (!s || !s->db || !project) { |
| 3154 | return CBM_STORE_ERR; |
| 3155 | } |
| 3156 | sqlite3_stmt *stmt = NULL; |
| 3157 | if (sqlite3_prepare_v2(s->db, |
| 3158 | "SELECT rel_path, kind, detail FROM index_coverage " |
| 3159 | "WHERE project = ?1 ORDER BY rel_path, kind;", |
| 3160 | CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 3161 | store_set_error_sqlite(s, "coverage get prepare"); |
| 3162 | return CBM_STORE_ERR; |
| 3163 | } |
| 3164 | bind_text(stmt, SKIP_ONE, project); |
| 3165 | int cap = ST_INIT_CAP_16; |
| 3166 | int n = 0; |
| 3167 | cbm_coverage_row_t *arr = malloc(cap * sizeof(cbm_coverage_row_t)); |
| 3168 | int scan_rc6; |
| 3169 | while ((scan_rc6 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 3170 | if (n >= cap) { |
| 3171 | cap *= ST_GROWTH; |
| 3172 | arr = safe_realloc(arr, cap * sizeof(cbm_coverage_row_t)); |
| 3173 | } |
| 3174 | arr[n].rel_path = heap_strdup((const char *)sqlite3_column_text(stmt, 0)); |
| 3175 | arr[n].kind = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE)); |
| 3176 | arr[n].detail = heap_strdup((const char *)sqlite3_column_text(stmt, CBM_SZ_2)); |
| 3177 | n++; |
| 3178 | } |
| 3179 | if (scan_rc6 != SQLITE_DONE) { /* SCANCHK:6:stmt */ |
| 3180 | store_set_error_sqlite(s, "row scan aborted"); |
| 3181 | sqlite3_finalize(stmt); |
| 3182 | cbm_store_free_coverage(arr, n); |
| 3183 | *out = NULL; |
| 3184 | *count = 0; |
| 3185 | return CBM_STORE_ERR; |
| 3186 | } |
| 3187 | sqlite3_finalize(stmt); |
| 3188 | *out = arr; |
| 3189 | *count = n; |
| 3190 | return CBM_STORE_OK; |
| 3191 | } |
| 3192 | |
| 3193 | void cbm_store_free_coverage(cbm_coverage_row_t *rows, int count) { |
| 3194 | if (!rows) { |
no test coverage detected