MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / coverage_query_rows

Function coverage_query_rows

src/store/store.c:3013–3065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3011}
3012
3013static int coverage_query_rows(cbm_store_t *s, const char *project, const char *selector,
3014 const char *sql, cbm_coverage_row_t **out, int *count) {
3015 if (!out || !count) {
3016 return CBM_STORE_ERR;
3017 }
3018 *out = NULL;
3019 *count = 0;
3020 if (!s || !s->db || !project || !selector || !sql) {
3021 return CBM_STORE_ERR;
3022 }
3023
3024 sqlite3_stmt *stmt = NULL;
3025 if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
3026 store_set_error_sqlite(s, "coverage targeted prepare");
3027 return CBM_STORE_ERR;
3028 }
3029 bind_text(stmt, SKIP_ONE, project);
3030 bind_text(stmt, ST_COL_2, selector);
3031
3032 int cap = ST_INIT_CAP_16;
3033 int n = 0;
3034 cbm_coverage_row_t *arr = malloc((size_t)cap * sizeof(*arr));
3035 if (!arr) {
3036 sqlite3_finalize(stmt);
3037 return CBM_STORE_ERR;
3038 }
3039 int scan_rc;
3040 while ((scan_rc = sqlite3_step(stmt)) == SQLITE_ROW) {
3041 if (n >= cap) {
3042 cap *= ST_GROWTH;
3043 arr = safe_realloc(arr, (size_t)cap * sizeof(*arr));
3044 }
3045 memset(&arr[n], 0, sizeof(arr[n]));
3046 arr[n].rel_path = heap_strdup((const char *)sqlite3_column_text(stmt, 0));
3047 arr[n].kind = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE));
3048 arr[n].detail = heap_strdup((const char *)sqlite3_column_text(stmt, ST_COL_2));
3049 if (!arr[n].rel_path || !arr[n].kind || !arr[n].detail) {
3050 sqlite3_finalize(stmt);
3051 cbm_store_free_coverage(arr, n + 1);
3052 return CBM_STORE_ERR;
3053 }
3054 n++;
3055 }
3056 sqlite3_finalize(stmt);
3057 if (scan_rc != SQLITE_DONE) {
3058 store_set_error_sqlite(s, "coverage targeted scan");
3059 cbm_store_free_coverage(arr, n);
3060 return CBM_STORE_ERR;
3061 }
3062 *out = arr;
3063 *count = n;
3064 return CBM_STORE_OK;
3065}
3066
3067int cbm_store_coverage_get_path(cbm_store_t *s, const char *project, const char *rel_path,
3068 cbm_coverage_row_t **out, int *count) {

Callers 2

Calls 5

store_set_error_sqliteFunction · 0.85
bind_textFunction · 0.85
safe_reallocFunction · 0.85
cbm_store_free_coverageFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected