| 1730 | } |
| 1731 | |
| 1732 | int cbm_store_delete_project(cbm_store_t *s, const char *name) { |
| 1733 | if (!s || !s->db || !name) { |
| 1734 | return CBM_STORE_ERR; |
| 1735 | } |
| 1736 | if (exec_sql(s, "BEGIN;") != CBM_STORE_OK) { |
| 1737 | return CBM_STORE_ERR; |
| 1738 | } |
| 1739 | |
| 1740 | static const char *cleanup_sql[] = { |
| 1741 | "DELETE FROM index_coverage WHERE project = ?1;", |
| 1742 | "DELETE FROM index_coverage_meta WHERE project = ?1;", |
| 1743 | "DELETE FROM projects WHERE name = ?1 || '::missed';", |
| 1744 | }; |
| 1745 | for (size_t i = 0; i < sizeof(cleanup_sql) / sizeof(cleanup_sql[0]); i++) { |
| 1746 | sqlite3_stmt *cleanup = NULL; |
| 1747 | if (sqlite3_prepare_v2(s->db, cleanup_sql[i], CBM_NOT_FOUND, &cleanup, NULL) != SQLITE_OK) { |
| 1748 | store_set_error_sqlite(s, "delete project coverage prepare"); |
| 1749 | (void)exec_sql(s, "ROLLBACK;"); |
| 1750 | return CBM_STORE_ERR; |
| 1751 | } |
| 1752 | bind_text(cleanup, SKIP_ONE, name); |
| 1753 | int cleanup_rc = sqlite3_step(cleanup); |
| 1754 | sqlite3_finalize(cleanup); |
| 1755 | if (cleanup_rc != SQLITE_DONE) { |
| 1756 | store_set_error_sqlite(s, "delete project coverage"); |
| 1757 | (void)exec_sql(s, "ROLLBACK;"); |
| 1758 | return CBM_STORE_ERR; |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | sqlite3_stmt *stmt = |
| 1763 | prepare_cached(s, &s->stmt_delete_project, "DELETE FROM projects WHERE name = ?1;"); |
| 1764 | if (!stmt) { |
| 1765 | (void)exec_sql(s, "ROLLBACK;"); |
| 1766 | return CBM_STORE_ERR; |
| 1767 | } |
| 1768 | |
| 1769 | bind_text(stmt, SKIP_ONE, name); |
| 1770 | int rc = sqlite3_step(stmt); |
| 1771 | if (rc != SQLITE_DONE) { |
| 1772 | store_set_error_sqlite(s, "delete_project"); |
| 1773 | (void)exec_sql(s, "ROLLBACK;"); |
| 1774 | return CBM_STORE_ERR; |
| 1775 | } |
| 1776 | return exec_sql(s, "COMMIT;"); |
| 1777 | } |
| 1778 | |
| 1779 | /* ── Node CRUD ──────────────────────────────────────────────────── */ |
| 1780 |
no test coverage detected