[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gnutrition] Another patch - database error "primary key must be uni
From: |
address@hidden |
Subject: |
[bug-gnutrition] Another patch - database error "primary key must be unique" while saving a recipe to database |
Date: |
Tue, 21 May 2013 00:33:52 -0400 |
Hi,
Here is another patch which I made since the program was crashing
everytime I tried to save more than one ingredient to a single recipe
in the database. It was because the primary key was set as the recipe
number which is not unique between ingredients within the same recipe.
I changed the primary key to the food number. So just as long as you
don't add the same food to a recipe more than once it won't crash.
Still not perfect but an improvement nonetheless. This patch includes
the previous one I proposed also since they are both so small.
- Jake
PS I know it has me logged in anonymously but my email is
address@hidden Feel free to message me about anything related to
the project.
---------------------------------------------------------------------------------
Only in .: patch.diff
diff -rc ./src/database.py ../gnutrition-0.32_changed/src/database.py
*** ./src/database.py 2012-09-01 12:43:08.000000000 -0400
--- ../gnutrition-0.32_changed/src/database.py 2013-05-21
00:09:35.968388136 -0400
***************
*** 176,185 ****
# create ingredient table
self.create_table("CREATE TABLE ingredient " +
! "(recipe_no INTEGER PRIMARY KEY NOT NULL, " +
"amount REAL NOT NULL, " +
"Msre_Desc TEXT NOT NULL, " +
! "NDB_No INTEGER NOT NULL)", 'ingredient')
# create recipe category table
self.create_load_table("CREATE TABLE category " +
--- 176,185 ----
# create ingredient table
self.create_table("CREATE TABLE ingredient " +
! "(recipe_no INTEGER NOT NULL, " +
"amount REAL NOT NULL, " +
"Msre_Desc TEXT NOT NULL, " +
! "NDB_No INTEGER PRIMARY KEY NOT NULL)", 'ingredient')
# create recipe category table
self.create_load_table("CREATE TABLE category " +
Only in ../gnutrition-0.32_changed/src: database.py~
diff -rc ./src/recipe_win.py ../gnutrition-0.32_changed/src/recipe_win.py
*** ./src/recipe_win.py 2012-09-01 12:43:08.000000000 -0400
--- ../gnutrition-0.32_changed/src/recipe_win.py 2013-05-20
14:56:23.575795964 -0400
***************
*** 320,329 ****
def add_ingredient(self, ingr):
match = 0
- ret = True
iter1 = self.ui.treemodel.get_iter_root()
if self.num_ingr > 0:
! while ret:
try:
ingr_in_recipe = self.ui.treemodel.get_value(iter1, 3)
except TypeError:
--- 320,328 ----
def add_ingredient(self, ingr):
match = 0
iter1 = self.ui.treemodel.get_iter_root()
if self.num_ingr > 0:
! while True:
try:
ingr_in_recipe = self.ui.treemodel.get_value(iter1, 3)
except TypeError:
***************
*** 331,337 ****
if ingr_in_recipe.food_num == ingr.food_num:
match = 1
break
! ret = self.ui.treemodel.iter_next(iter1)
if match == 0:
iter2 = self.ui.treemodel.append()
--- 330,336 ----
if ingr_in_recipe.food_num == ingr.food_num:
match = 1
break
! iter1 = self.ui.treemodel.iter_next(iter1)
if match == 0:
iter2 = self.ui.treemodel.append()
Only in ../gnutrition-0.32_changed/src: recipe_win.py~
patch.diff
Description: Binary data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug-gnutrition] Another patch - database error "primary key must be unique" while saving a recipe to database,
address@hidden <=