| 52 | } |
| 53 | |
| 54 | u8 *db_datastore_get(const tal_t *ctx, |
| 55 | struct db *db, |
| 56 | const char **key, |
| 57 | u64 *generation) |
| 58 | { |
| 59 | struct db_stmt *stmt; |
| 60 | u8 *ret; |
| 61 | |
| 62 | stmt = db_prepare_v2(db, |
| 63 | SQL("SELECT data, generation" |
| 64 | " FROM datastore" |
| 65 | " WHERE key = ?")); |
| 66 | db_bind_datastore_key(stmt, key); |
| 67 | db_query_prepared(stmt); |
| 68 | |
| 69 | if (!db_step(stmt)) { |
| 70 | tal_free(stmt); |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | ret = db_col_arr(ctx, stmt, "data", u8); |
| 75 | if (generation) |
| 76 | *generation = db_col_u64(stmt, "generation"); |
| 77 | else |
| 78 | db_col_ignore(stmt, "generation"); |
| 79 | tal_free(stmt); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | static const char **db_col_datastore_key(const tal_t *ctx, |
| 84 | struct db_stmt *stmt, |
no test coverage detected