def get_all_items_of_group(self, group_id, shoppinglist_id): """ Julius - returns all listentries where group_id and shoppinglist_id are like params similar too "get_items_of_group" but includes bought items """ result = [] cursor = self._cnx.cursor() statement = "SELECT Listentry.ID, Article.name as 'name', Category.name as 'category', Listentry.amount, Listentry.unit, Listentry.Retailer_ID, Listentry.Shoppinglist_ID as 'shoppinglist_id', Listentry.User_ID as 'user_id', Retailer.name as 'retailer', Listentry.Group_ID as 'group_id', Listentry.Article_ID as 'article_id' FROM Listentry LEFT JOIN Retailer ON Listentry.Retailer_ID = Retailer.ID LEFT JOIN Article ON Listentry.Article_ID = Article.ID LEFT JOIN Category ON Article.CategoryID = Category.ID WHERE (Group_ID={0} AND Shoppinglist_ID={1})".format( group_id, shoppinglist_id) cursor.execute(statement) tuples = cursor.fetchall() for (id, name, category, amount, unit, retailer_id, shoppinglist_id, user_id, retailer, group_id, article_id) in tuples: listentry = ListEntry() listentry.set_id(id) listentry.set_name(name) listentry.set_category(category) listentry.set_amount(amount) listentry.set_unit(unit) listentry.set_retailer_id(retailer_id) listentry.set_shoppinglist(shoppinglist_id) listentry.set_purchaser(user_id) listentry.set_retailer(retailer) listentry.set_group(group_id) listentry.set_article(article_id) result.append(listentry) self._cnx.commit() cursor.close() return result
def get_items_of_group(self, group_id, shoppinglist_id): """ Niklas - gets all listentries from the database for a specific group id, shoppinglist idcombination :return: a list of listentry bos """ result = [] cursor = self._cnx.cursor() statement = "SELECT Listentry.ID, Article.name as 'name', Category.name as 'category', Listentry.amount, Listentry.unit, Listentry.Retailer_ID, Listentry.Shoppinglist_ID as 'shoppinglist_id', Listentry.User_ID as 'user_id', Retailer.name as 'retailer', Listentry.Group_ID as 'group_id', Listentry.Article_ID as 'article_id' FROM Listentry LEFT JOIN Retailer ON Listentry.Retailer_ID = Retailer.ID LEFT JOIN Article ON Listentry.Article_ID = Article.ID LEFT JOIN Category ON Article.CategoryID = Category.ID WHERE (Group_ID={0} AND Shoppinglist_ID={1} AND (bought is NULL))".format( group_id, shoppinglist_id) cursor.execute(statement) tuples = cursor.fetchall() for (id, name, category, amount, unit, retailer_id, shoppinglist_id, user_id, retailer, group_id, article_id) in tuples: listentry = ListEntry() listentry.set_id(id) listentry.set_name(name) listentry.set_category(category) listentry.set_amount(amount) listentry.set_unit(unit) listentry.set_retailer_id(retailer_id) listentry.set_shoppinglist(shoppinglist_id) listentry.set_purchaser(user_id) listentry.set_retailer(retailer) listentry.set_group(group_id) listentry.set_article(article_id) result.append(listentry) self._cnx.commit() cursor.close() return result