| 90 | } |
| 91 | |
| 92 | struct db_stmt *db_prepare_v2_(const char *location, struct db *db, |
| 93 | const char *query_id) |
| 94 | { |
| 95 | size_t pos; |
| 96 | |
| 97 | /* Normalize query_id paths, because unit tests are compiled with this |
| 98 | * prefix. */ |
| 99 | if (strncmp(query_id, "./", 2) == 0) |
| 100 | query_id += 2; |
| 101 | |
| 102 | if (!db->in_transaction) |
| 103 | db_fatal("Attempting to prepare a db_stmt outside of a " |
| 104 | "transaction: %s", location); |
| 105 | |
| 106 | /* Look up the query by its ID */ |
| 107 | pos = hash_djb2(query_id) % db->queries->query_table_size; |
| 108 | for (;;) { |
| 109 | if (!db->queries->query_table[pos].name) |
| 110 | db_fatal("Could not resolve query %s", query_id); |
| 111 | if (streq(query_id, db->queries->query_table[pos].name)) |
| 112 | break; |
| 113 | pos = (pos + 1) % db->queries->query_table_size; |
| 114 | } |
| 115 | |
| 116 | return db_prepare_core(db, location, &db->queries->query_table[pos]); |
| 117 | } |
| 118 | |
| 119 | /* Provides replication and hook interface for raw SQL too */ |
| 120 | struct db_stmt *db_prepare_untranslated(struct db *db, const char *query) |
nothing calls this directly
no test coverage detected