1#include <stdio.h>
 2#include <stdlib.h>
 3#include <string.h>
 4
 5#include "sqlite3.h"
 6#include "data.h"
 7
 8int main(void) {
 9	sqlite3 *db;
10	int rc;
11
12	rc = sqlite3_open(":memory:", &db);
13	if (rc != SQLITE_OK) {
14		fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
15		return 1;
16	}
17
18	rc = sqlite3_deserialize(db, "main", data, data_len, data_len, SQLITE_DESERIALIZE_READONLY);
19	if (rc != SQLITE_OK) {
20		fprintf(stderr, "Failed to load database: %s\n", sqlite3_errmsg(db));
21		sqlite3_close(db);
22		return 1;
23	}
24
25	printf("Database loaded successfully!\n");
26
27	sqlite3_stmt *stmt;
28	const char *sql = "SELECT name FROM sqlite_master WHERE type='table';";
29	rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
30	if (rc == SQLITE_OK) {
31		printf("Tables in database:\n");
32		while (sqlite3_step(stmt) == SQLITE_ROW) {
33			printf("- %s\n", sqlite3_column_text(stmt, 0));
34		}
35		sqlite3_finalize(stmt);
36	}
37
38	sqlite3_close(db);
39	return 0;
40}