Add error checking to some DB functions
This commit is contained in:
parent
6c3ee3efda
commit
f45d893b47
21
wmud/db.c
21
wmud/db.c
@ -91,6 +91,7 @@ wmud_db_load_players(GError **err)
|
|||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res;
|
GdaDataModel *res;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
GError *local_err = NULL;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
@ -101,7 +102,15 @@ wmud_db_load_players(GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, login, password, email FROM players", NULL, NULL);
|
sth = gda_sql_parser_parse_string(parser, "SELECT id, login, password, email FROM players", NULL, NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
|
||||||
|
/* TODO: error checking! */
|
||||||
|
if ((res = gda_connection_statement_execute_select(dbh, sth, NULL, &local_err)) == NULL) {
|
||||||
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Unable to load players: %s", local_err->message);
|
||||||
|
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR, "SELECT error: %s", local_err->message);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
@ -287,8 +296,10 @@ wmud_db_load_directions(GSList **directions, GError **err)
|
|||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
GError *local_err = NULL;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading directions");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading directions");
|
||||||
|
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
||||||
@ -297,7 +308,13 @@ wmud_db_load_directions(GSList **directions, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, short_name, name FROM directions", NULL, NULL);
|
sth = gda_sql_parser_parse_string(parser, "SELECT id, short_name, name FROM directions", NULL, NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
|
||||||
|
if ((res = gda_connection_statement_execute_select(dbh, sth, NULL, &local_err)) == NULL) {
|
||||||
|
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR, "Unable to load directions: %s", local_err->message);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
|
@ -37,7 +37,8 @@ GQuark wmud_db_error_quark();
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
WMUD_DB_ERROR_CANTOPEN,
|
WMUD_DB_ERROR_CANTOPEN,
|
||||||
WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR_NOINIT,
|
||||||
WMUD_DB_ERROR_BADQUERY
|
WMUD_DB_ERROR_BADQUERY,
|
||||||
|
WMUD_DB_ERROR_SELECT_ERROR
|
||||||
} wmudDbError;
|
} wmudDbError;
|
||||||
|
|
||||||
gboolean wmud_db_init(GError **err);
|
gboolean wmud_db_init(GError **err);
|
||||||
|
Loading…
Reference in New Issue
Block a user