54 log_msg(ERROR,
"Potion",
"Database connection is not open");
60 int rc = sqlite3_prepare_v2(db_connection->db, SQL_SELECT_ALL_POTIONS, -1, &stmt, NULL);
61 if (rc != SQLITE_OK) {
62 log_msg(ERROR,
"Potion",
"Failed to prepare statement: %s", sqlite3_errmsg(db_connection->db));
68 if (potion_counted <= 0) {
69 log_msg(ERROR,
"Potion",
"No potions found in the database");
70 sqlite3_finalize(stmt);
74 if (potion_init_table == NULL) {
75 log_msg(ERROR,
"Potion",
"Failed to allocate memory for potion table");
76 sqlite3_finalize(stmt);
81 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW && index < potion_counted) {
82 potion_init_table[index].potion_type = sqlite3_column_int(stmt, 0);
83 potion_init_table[index].name = strdup((
const char*) sqlite3_column_text(stmt, 1));
84 potion_init_table[index].value = sqlite3_column_int(stmt, 2);
87 if (rc != SQLITE_DONE) {
88 log_msg(ERROR,
"Potion",
"Failed to execute statement: %s", sqlite3_errmsg(db_connection->db));
89 free(potion_init_table);
90 sqlite3_finalize(stmt);
94 sqlite3_finalize(stmt);
95 return potion_init_table;
111 log_msg(ERROR,
"Potion",
"Database connection is not open");
115 sqlite3_stmt* stmt_count;
116 int rc = sqlite3_prepare_v2(db_connection->db, SQL_SELECT_COUNT_POTIONS, -1, &stmt_count, NULL);
117 if (rc != SQLITE_OK) {
118 log_msg(ERROR,
"Potion",
"Failed to prepare statement: %s", sqlite3_errmsg(db_connection->db));
122 rc = sqlite3_step(stmt_count);
123 if (rc != SQLITE_ROW) {
124 log_msg(ERROR,
"Potion",
"Failed to execute statement: %s", sqlite3_errmsg(db_connection->db));
125 sqlite3_finalize(stmt_count);
129 const int potion_count = sqlite3_column_int(stmt_count, 0);
130 sqlite3_finalize(stmt_count);
132 if (potion_count == 0) {
133 log_msg(ERROR,
"Potion",
"No potions found in the database");
142 log_msg(ERROR,
"Gear",
"Database connection is not open");
147 int rc = sqlite3_prepare_v2(db_connection->db, SQL_SELECT_ALL_GEARS, -1, &stmt, NULL);
148 if (rc != SQLITE_OK) {
149 log_msg(ERROR,
"Gear",
"Failed to prepare statement: %s", sqlite3_errmsg(db_connection->db));
155 if (gear_counted <= 0) {
156 log_msg(ERROR,
"Gear",
"No gears found in the database");
157 sqlite3_finalize(stmt);
161 if (gear_init_table == NULL) {
162 log_msg(ERROR,
"Gear",
"Failed to allocate memory for gear table");
163 sqlite3_finalize(stmt);
168 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW && index < gear_counted) {
169 gear_init_table[index].name = strdup((
const char*) sqlite3_column_text(stmt, 0));
170 gear_init_table[index].gear_identifier = sqlite3_column_int(stmt, 1);
171 gear_init_table[index].slot = (gear_slot_t) sqlite3_column_int(stmt, 2);
172 gear_init_table[index].defenses.armor = sqlite3_column_int(stmt, 3);
173 gear_init_table[index].defenses.magic_resist = sqlite3_column_int(stmt, 4);
174 gear_init_table[index].stats.strength = sqlite3_column_int(stmt, 5);
175 gear_init_table[index].stats.dexterity = sqlite3_column_int(stmt, 6);
176 gear_init_table[index].stats.intelligence = sqlite3_column_int(stmt, 7);
177 gear_init_table[index].stats.constitution = sqlite3_column_int(stmt, 8);
178 gear_init_table[index].num_abilities = sqlite3_column_int(stmt, 9);
179 gear_init_table[index].ability_names[0] = sqlite3_column_int(stmt, 10);
180 gear_init_table[index].ability_names[1] = sqlite3_column_int(stmt, 11);
181 gear_init_table[index].ability_names[2] = sqlite3_column_int(stmt, 12);
182 gear_init_table[index].ability_names[3] = sqlite3_column_int(stmt, 13);
185 if (rc != SQLITE_DONE) {
186 log_msg(ERROR,
"Gear",
"Failed to execute statement: %s", sqlite3_errmsg(db_connection->db));
187 free(gear_init_table);
188 sqlite3_finalize(stmt);
192 sqlite3_finalize(stmt);
193 return gear_init_table;
209 log_msg(ERROR,
"Gear",
"Database connection is not open");
213 sqlite3_stmt* stmt_count;
214 int rc = sqlite3_prepare_v2(db_connection->db, SQL_SELECT_COUNT_GEARS, -1, &stmt_count, NULL);
215 if (rc != SQLITE_OK) {
216 log_msg(ERROR,
"Gear",
"Failed to prepare statement: %s", sqlite3_errmsg(db_connection->db));
220 rc = sqlite3_step(stmt_count);
221 if (rc != SQLITE_ROW) {
222 log_msg(ERROR,
"Gear",
"Failed to execute statement: %s", sqlite3_errmsg(db_connection->db));
223 sqlite3_finalize(stmt_count);
227 const int gear_count = sqlite3_column_int(stmt_count, 0);
228 sqlite3_finalize(stmt_count);
230 if (gear_count == 0) {
231 log_msg(ERROR,
"Gear",
"No gears found in 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.