add delete option and error handling to tours

This commit is contained in:
2019-01-17 09:59:06 -03:00
parent c659ab03e0
commit 6cb6283af0
4 changed files with 88 additions and 10 deletions

View File

@@ -129,6 +129,29 @@ namespace LibSernatur {
#endif
}
}
/**
* Delete a tour in the database
* @param conn The database connection
* @param tour The tour to update
* @throws DBError Thrown if the data in the object is invalid
*/
public static void delete_tour (Database conn, Tour tour) throws DBError {
if (tour.id_tour == 0) {
throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!"));
}
var res = conn.exec (Query.get_query (Query.Type.DELETE_TOUR, tour));
if (res.get_status () != ExecStatus.COMMAND_OK) {
if (res.get_error_field (FieldCode.SQLSTATE) == "23503") {
throw new DBError.FOREIGN_KEY_CONSTAINT (res.get_error_field (FieldCode.MESSAGE_PRIMARY));
}
#if DEBUG
error (conn.get_error_message ());
#else
warning (conn.get_error_message ());
#endif
}
}
}
}
}