| 888 | /* ── the graph ───────────────────────────────────────────────────── */ |
| 889 | |
| 890 | static int dg_db_edges(const char *db, const char *type, const char *src_suffix, |
| 891 | const char *tgt_suffix, const char *props_part) { |
| 892 | sqlite3 *h = NULL; |
| 893 | int n = 0; |
| 894 | if (sqlite3_open_v2(db, &h, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { |
| 895 | sqlite3_close(h); |
| 896 | return -1; |
| 897 | } |
| 898 | sqlite3_stmt *st = NULL; |
| 899 | const char *sql = "SELECT e.properties FROM edges e JOIN nodes s ON s.id = e.source_id " |
| 900 | "JOIN nodes t ON t.id = e.target_id WHERE e.type = ?1 " |
| 901 | "AND s.qualified_name LIKE '%' || ?2 AND t.qualified_name LIKE '%' || ?3"; |
| 902 | if (sqlite3_prepare_v2(h, sql, -1, &st, NULL) == SQLITE_OK) { |
| 903 | sqlite3_bind_text(st, 1, type, -1, SQLITE_TRANSIENT); |
| 904 | sqlite3_bind_text(st, 2, src_suffix, -1, SQLITE_TRANSIENT); |
| 905 | sqlite3_bind_text(st, 3, tgt_suffix, -1, SQLITE_TRANSIENT); |
| 906 | while (sqlite3_step(st) == SQLITE_ROW) { |
| 907 | const char *p = (const char *)sqlite3_column_text(st, 0); |
| 908 | n += !props_part || (p && strstr(p, props_part)); |
| 909 | } |
| 910 | } |
| 911 | sqlite3_finalize(st); |
| 912 | sqlite3_close(h); |
| 913 | if (n != 1) { |
| 914 | printf(" %s %s -> %s (%s): %d found\n", type, src_suffix, tgt_suffix, |
| 915 | props_part ? props_part : "", n); |
| 916 | } |
| 917 | return n; |
| 918 | } |
| 919 | |
| 920 | TEST(diagrams_graph) { |
| 921 | char tmp[256]; |