| 10622 | } |
| 10623 | |
| 10624 | static int arch_clusters(cbm_store_t *s, const char *project, const char *path, |
| 10625 | cbm_architecture_info_t *out) { |
| 10626 | char norm[CBM_SZ_512]; |
| 10627 | char like[CBM_SZ_512]; |
| 10628 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 10629 | char nsqlbuf[ST_SQL_BUF]; |
| 10630 | const char *nbase = "SELECT id, name, qualified_name, file_path FROM nodes " |
| 10631 | "WHERE project=?1 AND label IN (" CBM_SQL_CALLABLE_OR_TYPE_LABELS |
| 10632 | "," CBM_SQL_RELATION_LABELS ")"; |
| 10633 | if (scoped) { |
| 10634 | snprintf(nsqlbuf, sizeof(nsqlbuf), "%s%s ORDER BY id LIMIT ?4", nbase, |
| 10635 | arch_path_scope_sql()); |
| 10636 | } else { |
| 10637 | snprintf(nsqlbuf, sizeof(nsqlbuf), "%s ORDER BY id LIMIT ?2", nbase); |
| 10638 | } |
| 10639 | sqlite3_stmt *st = NULL; |
| 10640 | if (sqlite3_prepare_v2(s->db, nsqlbuf, CBM_NOT_FOUND, &st, NULL) != SQLITE_OK) { |
| 10641 | return CBM_STORE_OK; /* clusters are best-effort */ |
| 10642 | } |
| 10643 | bind_text(st, SKIP_ONE, project); |
| 10644 | if (scoped) { |
| 10645 | arch_bind_path_scope(st, ST_COL_2, ST_COL_3, norm, like); |
| 10646 | sqlite3_bind_int(st, ST_COL_4, CBM_CLUSTER_NODE_CAP); |
| 10647 | } else { |
| 10648 | sqlite3_bind_int(st, CBM_SZ_2, CBM_CLUSTER_NODE_CAP); |
| 10649 | } |
| 10650 | int cap = ST_INIT_CAP_8; |
| 10651 | int n = 0; |
| 10652 | int64_t *ids = malloc((size_t)cap * sizeof(int64_t)); |
| 10653 | const char **names = malloc((size_t)cap * sizeof(char *)); |
| 10654 | const char **qns = malloc((size_t)cap * sizeof(char *)); |
| 10655 | int scan_rc29; |
| 10656 | while ((scan_rc29 = sqlite3_step(st)) == SQLITE_ROW) { |
| 10657 | if (n >= cap) { |
| 10658 | cap *= ST_GROWTH; |
| 10659 | ids = safe_realloc(ids, (size_t)cap * sizeof(int64_t)); |
| 10660 | names = safe_realloc(names, (size_t)cap * sizeof(char *)); |
| 10661 | qns = safe_realloc(qns, (size_t)cap * sizeof(char *)); |
| 10662 | } |
| 10663 | ids[n] = sqlite3_column_int64(st, 0); |
| 10664 | names[n] = heap_strdup((const char *)sqlite3_column_text(st, SKIP_ONE)); |
| 10665 | qns[n] = heap_strdup((const char *)sqlite3_column_text(st, CBM_SZ_2)); |
| 10666 | n++; |
| 10667 | } |
| 10668 | if (scan_rc29 != SQLITE_DONE) { /* SCANCHK:29:st */ |
| 10669 | store_set_error_sqlite(s, "row scan aborted"); |
| 10670 | sqlite3_finalize(st); |
| 10671 | for (int ci = 0; ci < n; ci++) { |
| 10672 | safe_str_free(&names[ci]); |
| 10673 | safe_str_free(&qns[ci]); |
| 10674 | } |
| 10675 | free(ids); |
| 10676 | free((void *)names); |
| 10677 | free((void *)qns); |
| 10678 | return CBM_STORE_ERR; |
| 10679 | } |
| 10680 | sqlite3_finalize(st); |
| 10681 | if (n < CBM_CLUSTER_MIN_MEMBERS) { |
no test coverage detected