13 int rc = sqlite3_open(db_name, &db_connection->db);
15 log_msg(ERROR,
"Database",
"Can't open database: %s", sqlite3_errmsg(db_connection->db));
16 return DB_OPEN_STATUS_FAILURE;
18 return DB_OPEN_STATUS_SUCCESS;
23 sqlite3_close(db_connection->db);
24 db_connection->db = NULL;
28 if (db_connection->db == NULL) {
35 const char* potential_paths[3];
38 potential_paths[0] = DB_BUILD_DIR_PATH(dungeoncrawl_game.db);
39 potential_paths[1] = DB_RESOURCE_PATH(game, dungeoncrawl_game.db);
40 potential_paths[2] = DB_RESOURCE_PATH_UP(game, dungeoncrawl_game.db);
43 potential_paths[0] = DB_BUILD_DIR_PATH(dungeoncrawl_local.db);
44 potential_paths[1] = DB_RESOURCE_PATH(local, dungeoncrawl_local.db);
45 potential_paths[2] = DB_RESOURCE_PATH_UP(local, dungeoncrawl_local.db);
48 log_msg(ERROR,
"Database",
"Invalid database type");
49 return DB_OPEN_STATUS_FAILURE;
52 for (
int i = 0; i <
sizeof(potential_paths) /
sizeof(
char*); i++) {
53 const int rc = sqlite3_open_v2(potential_paths[i], &db_connection->db, SQLITE_OPEN_READWRITE, NULL);
54 if (rc == SQLITE_OK) {
55 return DB_OPEN_STATUS_SUCCESS;
57 log_msg(WARNING,
"Database",
"Can't open database: %s", sqlite3_errmsg(db_connection->db));
59 return DB_OPEN_STATUS_FAILURE;
int db_is_open(const db_connection_t *db_connection)
This function is to check if the database is open.
int db_open(db_connection_t *db_connection, const char *db_name)
This function is for the opening of the database.
int db_open_multiple_access(db_connection_t *db_connection, db_type_t type)
This function is for the opening of the database with multiple access.
void db_close(db_connection_t *db_connection)
This function is for the closing of the database.
Exposes functions for working with the database.
void log_msg(const log_level_t level, const char *module, const char *format,...)
Logs a formatted message with a specified log level and module.
Header file for logging functionality of the game.
This struct is used for the database connection in SQLite.