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

Function coverage_query_rows

src/store/store.c:4943–4995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4941}
4942
4943static int coverage_query_rows(cbm_store_t *s, const char *project, const char *selector,
4944 const char *sql, cbm_coverage_row_t **out, int *count) {
4945 if (!out || !count) {
4946 return CBM_STORE_ERR;
4947 }
4948 *out = NULL;
4949 *count = 0;
4950 if (!s || !s->db || !project || !selector || !sql) {
4951 return CBM_STORE_ERR;
4952 }
4953
4954 sqlite3_stmt *stmt = NULL;
4955 if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
4956 store_set_error_sqlite(s, "coverage targeted prepare");
4957 return CBM_STORE_ERR;
4958 }
4959 bind_text(stmt, SKIP_ONE, project);
4960 bind_text(stmt, ST_COL_2, selector);
4961
4962 int cap = ST_INIT_CAP_16;
4963 int n = 0;
4964 cbm_coverage_row_t *arr = malloc((size_t)cap * sizeof(*arr));
4965 if (!arr) {
4966 sqlite3_finalize(stmt);
4967 return CBM_STORE_ERR;
4968 }
4969 int scan_rc;
4970 while ((scan_rc = sqlite3_step(stmt)) == SQLITE_ROW) {
4971 if (n >= cap) {
4972 cap *= ST_GROWTH;
4973 arr = safe_realloc(arr, (size_t)cap * sizeof(*arr));
4974 }
4975 memset(&arr[n], 0, sizeof(arr[n]));
4976 arr[n].rel_path = heap_strdup((const char *)sqlite3_column_text(stmt, 0));
4977 arr[n].kind = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE));
4978 arr[n].detail = heap_strdup((const char *)sqlite3_column_text(stmt, ST_COL_2));
4979 if (!arr[n].rel_path || !arr[n].kind || !arr[n].detail) {
4980 sqlite3_finalize(stmt);
4981 cbm_store_free_coverage(arr, n + 1);
4982 return CBM_STORE_ERR;
4983 }
4984 n++;
4985 }
4986 sqlite3_finalize(stmt);
4987 if (scan_rc != SQLITE_DONE) {
4988 store_set_error_sqlite(s, "coverage targeted scan");
4989 cbm_store_free_coverage(arr, n);
4990 return CBM_STORE_ERR;
4991 }
4992 *out = arr;
4993 *count = n;
4994 return CBM_STORE_OK;
4995}
4996
4997int cbm_store_coverage_get_path(cbm_store_t *s, const char *project, const char *rel_path,
4998 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