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

Function cbm_store_doc_links_replace

src/store/store.c:5173–5229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5171}
5172
5173int cbm_store_doc_links_replace(cbm_store_t *s, const char *project, const cbm_doc_link_row_t *rows,
5174 int count) {
5175 if (!s || !s->db || !project || count < 0 || (count > 0 && !rows)) {
5176 return CBM_STORE_ERR;
5177 }
5178 if (exec_sql(s, DOC_LINKS_DDL) != CBM_STORE_OK) {
5179 return CBM_STORE_ERR;
5180 }
5181 if (exec_sql(s, "BEGIN;") != CBM_STORE_OK) {
5182 return CBM_STORE_ERR;
5183 }
5184 sqlite3_stmt *del = NULL;
5185 if (sqlite3_prepare_v2(s->db, "DELETE FROM doc_link_unresolved WHERE project = ?1;",
5186 CBM_NOT_FOUND, &del, NULL) != SQLITE_OK) {
5187 store_set_error_sqlite(s, "doc_links delete prepare");
5188 (void)exec_sql(s, "ROLLBACK;");
5189 return CBM_STORE_ERR;
5190 }
5191 bind_text(del, SKIP_ONE, project);
5192 int rc = sqlite3_step(del);
5193 sqlite3_finalize(del);
5194 if (rc != SQLITE_DONE) {
5195 store_set_error_sqlite(s, "doc_links delete");
5196 (void)exec_sql(s, "ROLLBACK;");
5197 return CBM_STORE_ERR;
5198 }
5199 sqlite3_stmt *ins = NULL;
5200 if (sqlite3_prepare_v2(s->db,
5201 "INSERT INTO doc_link_unresolved "
5202 "(project, rel_path, line, syntax, raw, reason) "
5203 "VALUES (?1, ?2, ?3, ?4, ?5, ?6);",
5204 CBM_NOT_FOUND, &ins, NULL) != SQLITE_OK) {
5205 store_set_error_sqlite(s, "doc_links insert prepare");
5206 (void)exec_sql(s, "ROLLBACK;");
5207 return CBM_STORE_ERR;
5208 }
5209 for (int i = 0; i < count; i++) {
5210 if (!rows[i].rel_path || !rows[i].reason) {
5211 continue;
5212 }
5213 bind_text(ins, SKIP_ONE, project);
5214 bind_text(ins, ST_COL_2, rows[i].rel_path);
5215 sqlite3_bind_int(ins, ST_COL_3, rows[i].line);
5216 bind_text(ins, CBM_SZ_4, rows[i].syntax ? rows[i].syntax : "");
5217 bind_text(ins, CBM_SZ_5, rows[i].raw ? rows[i].raw : "");
5218 bind_text(ins, CBM_SZ_6, rows[i].reason);
5219 if (sqlite3_step(ins) != SQLITE_DONE) {
5220 store_set_error_sqlite(s, "doc_links insert");
5221 sqlite3_finalize(ins);
5222 (void)exec_sql(s, "ROLLBACK;");
5223 return CBM_STORE_ERR;
5224 }
5225 sqlite3_reset(ins);
5226 }
5227 sqlite3_finalize(ins);
5228 return exec_sql(s, "COMMIT;");
5229}
5230

Callers 6

publish_doc_linksFunction · 0.85
dm_index_status_checksFunction · 0.85
dm_preview_bounds_checksFunction · 0.85
dm_preview_text_caseFunction · 0.85
dm_preview_order_checksFunction · 0.85

Calls 3

exec_sqlFunction · 0.85
store_set_error_sqliteFunction · 0.85
bind_textFunction · 0.85

Tested by 5

dm_index_status_checksFunction · 0.68
dm_preview_bounds_checksFunction · 0.68
dm_preview_text_caseFunction · 0.68
dm_preview_order_checksFunction · 0.68