I think you may benefit from normalizing your database structure.
Scenario a) violates 2nd normal form, and scenario b) violates 1st
normal form.

Something like this should work nicely:

--------------------
meals
--------------------
meal_id
meal_name

--------------------
meal_ingredients
--------------------
meal_id
ingredient_id

--------------------
ingredients
--------------------
ingredient_id
ingredient_name

To find out what's in a particular meal, you look in meal_ingredients
and get a list of all ingredient_id's belonging to the meal, then look
up the details of each ingredient based on the ingredient_id from
ingredients. Of course, if this were using a relational database
engine, you could get all this done with a single query using joins,
but using Palm you need to do a bit of the grunt work yourself. I
believe there actually are some commercial database platforms for Palm
which may do some of this for you, but they all have drawbacks
(certainly price would be one of them for a solo developer).

Adrien.

Monday, July 12, 2004, 10:45:38 AM, you wrote:

ah> I'm writing a calorie tracking app. Users will be able to create their own
ah> 'meals' using foods from the food database. e.g. hamburger =
ah> beef+cheese+bun. I'm a little undecided as to the best way of storing the
ah> recipes.

ah> a) I can have a DB called Meals which stores the name of each meal in it's
ah> own record. I have another DB called MealIngredients which stores the
ah> uniqueID of the food record for that ingredient and also the unique ID of
ah> the meal record in MealsDB.  To get all the ingredients for a given meal, I
ah> simply search for all records in the MealIngredients DB which contain the
ah> meals uniqueID

ah> b) I can have one database called meals, which stores a UInt16 holding the
ah> number of ingredients, followed by the uniqueID's (from the foodsDB) of all
ah> the ingredients, followed by the name.

ah> I'm more inclined to go with B) because presumably there's less overhead but
ah> what happens when a user deletes a food from the foods database? I'd have to
ah> iterate through every Meal record, unpacking and searching each one for the
ah> foods uniqueID. In the same scenario with option A, i can just run a
ah> DmComparF function to see if the food is in use.

ah> is either of these approaches more suited than the other to this particular
ah> app.  Is there another way of doing it that I've missed?

ah> any input appreciated




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to