Generic: find multiple nodes by a single-column filter. */
| 1359 | |
| 1360 | /* Generic: find multiple nodes by a single-column filter. */ |
| 1361 | static int find_nodes_generic(cbm_store_t *s, sqlite3_stmt **slot, const char *sql, |
| 1362 | const char *project, const char *val, cbm_node_t **out, int *count) { |
| 1363 | if (!s || !s->db) { |
| 1364 | *out = NULL; |
| 1365 | *count = 0; |
| 1366 | return CBM_STORE_ERR; |
| 1367 | } |
| 1368 | sqlite3_stmt *stmt = prepare_cached(s, slot, sql); |
| 1369 | if (!stmt) { |
| 1370 | return CBM_STORE_ERR; |
| 1371 | } |
| 1372 | |
| 1373 | bind_text(stmt, SKIP_ONE, project); |
| 1374 | bind_text(stmt, ST_COL_2, val); |
| 1375 | |
| 1376 | int cap = ST_INIT_CAP_16; |
| 1377 | int n = 0; |
| 1378 | cbm_node_t *arr = malloc(cap * sizeof(cbm_node_t)); |
| 1379 | |
| 1380 | while (sqlite3_step(stmt) == SQLITE_ROW) { |
| 1381 | if (n >= cap) { |
| 1382 | cap *= ST_GROWTH; |
| 1383 | arr = safe_realloc(arr, cap * sizeof(cbm_node_t)); |
| 1384 | } |
| 1385 | scan_node(stmt, &arr[n]); |
| 1386 | n++; |
| 1387 | } |
| 1388 | |
| 1389 | *out = arr; |
| 1390 | *count = n; |
| 1391 | return CBM_STORE_OK; |
| 1392 | } |
| 1393 | |
| 1394 | int cbm_store_find_nodes_by_name(cbm_store_t *s, const char *project, const char *name, |
| 1395 | cbm_node_t **out, int *count) { |
no test coverage detected