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

Function coverage_query_rows

src/store/store.c:3123–3175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3121}
3122
3123static int coverage_query_rows(cbm_store_t *s, const char *project, const char *selector,
3124 const char *sql, cbm_coverage_row_t **out, int *count) {
3125 if (!out || !count) {
3126 return CBM_STORE_ERR;
3127 }
3128 *out = NULL;
3129 *count = 0;
3130 if (!s || !s->db || !project || !selector || !sql) {
3131 return CBM_STORE_ERR;
3132 }
3133
3134 sqlite3_stmt *stmt = NULL;
3135 if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
3136 store_set_error_sqlite(s, "coverage targeted prepare");
3137 return CBM_STORE_ERR;
3138 }
3139 bind_text(stmt, SKIP_ONE, project);
3140 bind_text(stmt, ST_COL_2, selector);
3141
3142 int cap = ST_INIT_CAP_16;
3143 int n = 0;
3144 cbm_coverage_row_t *arr = malloc((size_t)cap * sizeof(*arr));
3145 if (!arr) {
3146 sqlite3_finalize(stmt);
3147 return CBM_STORE_ERR;
3148 }
3149 int scan_rc;
3150 while ((scan_rc = sqlite3_step(stmt)) == SQLITE_ROW) {
3151 if (n >= cap) {
3152 cap *= ST_GROWTH;
3153 arr = safe_realloc(arr, (size_t)cap * sizeof(*arr));
3154 }
3155 memset(&arr[n], 0, sizeof(arr[n]));
3156 arr[n].rel_path = heap_strdup((const char *)sqlite3_column_text(stmt, 0));
3157 arr[n].kind = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE));
3158 arr[n].detail = heap_strdup((const char *)sqlite3_column_text(stmt, ST_COL_2));
3159 if (!arr[n].rel_path || !arr[n].kind || !arr[n].detail) {
3160 sqlite3_finalize(stmt);
3161 cbm_store_free_coverage(arr, n + 1);
3162 return CBM_STORE_ERR;
3163 }
3164 n++;
3165 }
3166 sqlite3_finalize(stmt);
3167 if (scan_rc != SQLITE_DONE) {
3168 store_set_error_sqlite(s, "coverage targeted scan");
3169 cbm_store_free_coverage(arr, n);
3170 return CBM_STORE_ERR;
3171 }
3172 *out = arr;
3173 *count = n;
3174 return CBM_STORE_OK;
3175}
3176
3177int cbm_store_coverage_get_path(cbm_store_t *s, const char *project, const char *rel_path,
3178 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