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

Function coverage_query_rows

src/store/store.c:2912–2964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2910}
2911
2912static int coverage_query_rows(cbm_store_t *s, const char *project, const char *selector,
2913 const char *sql, cbm_coverage_row_t **out, int *count) {
2914 if (!out || !count) {
2915 return CBM_STORE_ERR;
2916 }
2917 *out = NULL;
2918 *count = 0;
2919 if (!s || !s->db || !project || !selector || !sql) {
2920 return CBM_STORE_ERR;
2921 }
2922
2923 sqlite3_stmt *stmt = NULL;
2924 if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
2925 store_set_error_sqlite(s, "coverage targeted prepare");
2926 return CBM_STORE_ERR;
2927 }
2928 bind_text(stmt, SKIP_ONE, project);
2929 bind_text(stmt, ST_COL_2, selector);
2930
2931 int cap = ST_INIT_CAP_16;
2932 int n = 0;
2933 cbm_coverage_row_t *arr = malloc((size_t)cap * sizeof(*arr));
2934 if (!arr) {
2935 sqlite3_finalize(stmt);
2936 return CBM_STORE_ERR;
2937 }
2938 int scan_rc;
2939 while ((scan_rc = sqlite3_step(stmt)) == SQLITE_ROW) {
2940 if (n >= cap) {
2941 cap *= ST_GROWTH;
2942 arr = safe_realloc(arr, (size_t)cap * sizeof(*arr));
2943 }
2944 memset(&arr[n], 0, sizeof(arr[n]));
2945 arr[n].rel_path = heap_strdup((const char *)sqlite3_column_text(stmt, 0));
2946 arr[n].kind = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE));
2947 arr[n].detail = heap_strdup((const char *)sqlite3_column_text(stmt, ST_COL_2));
2948 if (!arr[n].rel_path || !arr[n].kind || !arr[n].detail) {
2949 sqlite3_finalize(stmt);
2950 cbm_store_free_coverage(arr, n + 1);
2951 return CBM_STORE_ERR;
2952 }
2953 n++;
2954 }
2955 sqlite3_finalize(stmt);
2956 if (scan_rc != SQLITE_DONE) {
2957 store_set_error_sqlite(s, "coverage targeted scan");
2958 cbm_store_free_coverage(arr, n);
2959 return CBM_STORE_ERR;
2960 }
2961 *out = arr;
2962 *count = n;
2963 return CBM_STORE_OK;
2964}
2965
2966int cbm_store_coverage_get_path(cbm_store_t *s, const char *project, const char *rel_path,
2967 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