| 2514 | } |
| 2515 | |
| 2516 | int cbm_store_delete_project(cbm_store_t *s, const char *name) { |
| 2517 | if (!s || !s->db || !name) { |
| 2518 | return CBM_STORE_ERR; |
| 2519 | } |
| 2520 | if (exec_sql(s, "BEGIN;") != CBM_STORE_OK) { |
| 2521 | return CBM_STORE_ERR; |
| 2522 | } |
| 2523 | |
| 2524 | static const char *cleanup_sql[] = { |
| 2525 | "DELETE FROM index_coverage WHERE project = ?1;", |
| 2526 | "DELETE FROM index_coverage_meta WHERE project = ?1;", |
| 2527 | "DELETE FROM projects WHERE name = ?1 || '::missed';", |
| 2528 | }; |
| 2529 | for (size_t i = 0; i < sizeof(cleanup_sql) / sizeof(cleanup_sql[0]); i++) { |
| 2530 | sqlite3_stmt *cleanup = NULL; |
| 2531 | if (sqlite3_prepare_v2(s->db, cleanup_sql[i], CBM_NOT_FOUND, &cleanup, NULL) != SQLITE_OK) { |
| 2532 | store_set_error_sqlite(s, "delete project coverage prepare"); |
| 2533 | (void)exec_sql(s, "ROLLBACK;"); |
| 2534 | return CBM_STORE_ERR; |
| 2535 | } |
| 2536 | bind_text(cleanup, SKIP_ONE, name); |
| 2537 | int cleanup_rc = sqlite3_step(cleanup); |
| 2538 | sqlite3_finalize(cleanup); |
| 2539 | if (cleanup_rc != SQLITE_DONE) { |
| 2540 | store_set_error_sqlite(s, "delete project coverage"); |
| 2541 | (void)exec_sql(s, "ROLLBACK;"); |
| 2542 | return CBM_STORE_ERR; |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | sqlite3_stmt *stmt = |
| 2547 | prepare_cached(s, &s->stmt_delete_project, "DELETE FROM projects WHERE name = ?1;"); |
| 2548 | if (!stmt) { |
| 2549 | (void)exec_sql(s, "ROLLBACK;"); |
| 2550 | return CBM_STORE_ERR; |
| 2551 | } |
| 2552 | |
| 2553 | bind_text(stmt, SKIP_ONE, name); |
| 2554 | int rc = sqlite3_step(stmt); |
| 2555 | if (rc != SQLITE_DONE) { |
| 2556 | store_set_error_sqlite(s, "delete_project"); |
| 2557 | (void)exec_sql(s, "ROLLBACK;"); |
| 2558 | return CBM_STORE_ERR; |
| 2559 | } |
| 2560 | return exec_sql(s, "COMMIT;"); |
| 2561 | } |
| 2562 | |
| 2563 | /* ── Node CRUD ──────────────────────────────────────────────────── */ |
| 2564 |
no test coverage detected