add delete option and error handling to tours
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user