| 3476 | } |
| 3477 | |
| 3478 | static int count_degrees_direction(cbm_store_t *s, const int64_t *node_ids, int id_count, |
| 3479 | const char *in_clause, bool has_type, const char *edge_type, |
| 3480 | bool inbound, int *out_counts) { |
| 3481 | char sql[ST_SQL_BUF]; |
| 3482 | const char *id_col = inbound ? "target_id" : "source_id"; |
| 3483 | if (has_type) { |
| 3484 | snprintf(sql, sizeof(sql), |
| 3485 | "SELECT %s, COUNT(*) FROM edges " |
| 3486 | "WHERE %s IN (%s) AND type = ? GROUP BY %s", |
| 3487 | id_col, id_col, in_clause, id_col); |
| 3488 | } else { |
| 3489 | snprintf(sql, sizeof(sql), |
| 3490 | "SELECT %s, COUNT(*) FROM edges " |
| 3491 | "WHERE %s IN (%s) GROUP BY %s", |
| 3492 | id_col, id_col, in_clause, id_col); |
| 3493 | } |
| 3494 | |
| 3495 | sqlite3_stmt *stmt = NULL; |
| 3496 | if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 3497 | return CBM_STORE_ERR; |
| 3498 | } |
| 3499 | |
| 3500 | for (int i = 0; i < id_count; i++) { |
| 3501 | sqlite3_bind_int64(stmt, i + SKIP_ONE, node_ids[i]); |
| 3502 | } |
| 3503 | if (has_type) { |
| 3504 | bind_text(stmt, id_count + SKIP_ONE, edge_type); |
| 3505 | } |
| 3506 | |
| 3507 | int scan_rc11; |
| 3508 | while ((scan_rc11 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 3509 | int64_t nid = sqlite3_column_int64(stmt, 0); |
| 3510 | int cnt = sqlite3_column_int(stmt, SKIP_ONE); |
| 3511 | for (int i = 0; i < id_count; i++) { |
| 3512 | if (node_ids[i] == nid) { |
| 3513 | out_counts[i] = cnt; |
| 3514 | break; |
| 3515 | } |
| 3516 | } |
| 3517 | } |
| 3518 | if (scan_rc11 != SQLITE_DONE) { /* SCANCHK:11:stmt */ |
| 3519 | store_set_error_sqlite(s, "row scan aborted"); |
| 3520 | sqlite3_finalize(stmt); |
| 3521 | return CBM_STORE_ERR; |
| 3522 | } |
| 3523 | sqlite3_finalize(stmt); |
| 3524 | return CBM_STORE_OK; |
| 3525 | } |
| 3526 | |
| 3527 | int cbm_store_batch_count_degrees(cbm_store_t *s, const int64_t *node_ids, int id_count, |
| 3528 | const char *edge_type, int *out_in, int *out_out) { |
no test coverage detected