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

Function cbm_cypher_execute

src/cypher/cypher.c:4866–4951  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4864/* ── Main entry point ─────────────────────────────────────────── */
4865
4866int cbm_cypher_execute(cbm_store_t *store, const char *query, const char *project, int max_rows,
4867 cbm_cypher_result_t *out) {
4868 memset(out, 0, sizeof(*out));
4869 g_cypher_depth_clamped = 0;
4870 cypher_deadline_arm(); /* #601: start the wall-clock budget for this query */
4871 if (max_rows <= 0) {
4872 max_rows = CYPHER_RESULT_CEILING;
4873 }
4874
4875 cbm_query_t *q = NULL;
4876 char *err = NULL;
4877 if (cbm_cypher_parse(query, &q, &err) < 0) {
4878 out->error = err;
4879 return CBM_NOT_FOUND;
4880 }
4881
4882 result_builder_t rb = {0};
4883 if (execute_single(store, q, project, max_rows, &rb) < 0) {
4884 rb_free(&rb);
4885 cbm_query_free(q);
4886 out->error = heap_strdup("query aborted: out of memory or an allocation limit was reached");
4887 return CBM_NOT_FOUND;
4888 }
4889
4890 /* UNION chain */
4891 cbm_query_t *uq = q->union_next;
4892 while (uq) {
4893 result_builder_t rb2 = {0};
4894 if (execute_single(store, uq, project, max_rows, &rb2) < 0) {
4895 rb_free(&rb);
4896 rb_free(&rb2);
4897 cbm_query_free(q);
4898 out->error =
4899 heap_strdup("query aborted: out of memory or an allocation limit was reached");
4900 return CBM_NOT_FOUND;
4901 }
4902 /* Concatenate rows from rb2 into rb */
4903 for (int i = 0; i < rb2.row_count; i++) {
4904 rb_add_row(&rb, rb2.rows[i]);
4905 }
4906 rb_free(&rb2);
4907
4908 uq = uq->union_next;
4909 }
4910
4911 /* UNION (not ALL) deduplication */
4912 if (q->union_next && !q->union_all) {
4913 rb_apply_distinct(&rb);
4914 }
4915
4916 /* #601: abort a runaway query that blew the wall-clock budget before it can
4917 * return a misleading partial result. Checked before the row ceiling. */
4918 if (g_cypher_timed_out) {
4919 rb_free(&rb);
4920 cbm_query_free(q);
4921 out->error =
4922 heap_strdup("query exceeded the execution time limit — narrow the pattern with a WHERE "
4923 "filter, use a directed MATCH instead of an unbounded OPTIONAL MATCH, or "

Callers 5

handle_query_graphFunction · 0.85
test_cypher.cFile · 0.85
test_security.cFile · 0.85

Calls 8

cypher_deadline_armFunction · 0.85
cbm_cypher_parseFunction · 0.85
execute_singleFunction · 0.85
rb_freeFunction · 0.85
cbm_query_freeFunction · 0.85
rb_add_rowFunction · 0.85
rb_apply_distinctFunction · 0.85
heap_strdupFunction · 0.70

Tested by 1