delving into sqlite.. I haven't DB'd in a while..
but can you do this?
Recipes Table | | |
ID | Item | Count |
13679 | Taco | 2 |
| Lettuce | 3 |
| Tomatoes | 44 |
| | |
13639 | Burro | 2 |
| Lettuce | 3 |
| Tomatoes | 44 |
And just reference the ID and pull individual records under that ID?
The goal is to say.. I want info about ID 13639.. and I want to grab one by one everything under that id that is an item.. are blank spaces in the first field OK?
From a pure data normalization perspective, you'd want to have separate tables. One for Recipes, another for Components (or Ingredients, Materials/Mats, etc.), and a third for RecipeComponents (combining the two). The insures you have all the recipes and components defined before you start trying to put the two together. You can get away with just two tables if you don't care about the integrity of the combinations (i.e., both a taco and a salad use lettuce and referencing "lettuce" in both places is not relevant to putting it together).
[CODE lang="sql" title="Recipes"]CREATE TABLE IF NOT EXISTS "Recipes"
(
[RecipeId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[Name] NVARCHAR(255) NOT NULL,
[ResultAmount] INTEGER NOT NULL
);
CREATE INDEX [IFK_RecipeId] ON "Recipes" ([RecipeId]);
[/CODE]
[CODE lang="sql" title="Components"]CREATE TABLE IF NOT EXISTS "Components"
(
[ComponentId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[Name] NVARCHAR(255) NOT NULL
);
CREATE INDEX [IFK_ComponentId] ON "Components" ([ComponentId]);
[/CODE]
[CODE lang="sql" title="RecipeComponents"]CREATE TABLE IF NOT EXISTS "RecipeComponents"
(
[RecipeId] INTEGER NOT NULL,
[ComponentId] INTEGER NOT NULL,
[Name] NVARCHAR(255) NOT NULL,
[Count] INTEGER NOT NULL,
FOREIGN KEY ([RecipeId]) REFERENCES "Recipes" ([RecipeId])
ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY ([ComponentId]) REFERENCES "Components" ([ComponentId])
ON DELETE NO ACTION ON UPDATE NO ACTION,
PRIMARY KEY(RecipeId,ComponentId)
);
[/CODE]
I don't know that you really care how many are the result of a success or what you may get back on success or failure (i.e., using planing tool in fletching would always be returned). I'm not sure I'd recommend having an autoincrement on your tables either depending on the source for your recipes. If you're pulling them from EQ Traders or ZAM, you might be better of using their numbers to maintain consistency. If you're pulling from multiple sources and mixing them together, stick to your own numbering. You'll have to figure out how to disambiguate those recipes/components with the same name that aren't the exact same result, though.