def get(type,id)
check_dbh
case type
when 'cookbook'
raise "Invalid Record ID" if @dbh.select_one('select * from cookbook where cookbook_id=?', id).nil?
@hash['cookbook'] = Hash.new if @hash['cookbook'].nil?
@hash['cookbook'][id] = Cookbook.new(@dbh, id) if @hash['cookbook'][id].nil?
return @hash['cookbook'][id]
when 'category'
raise "Invalid Record ID" if @dbh.select_one('select * from category where category_id=?', id).nil?
@hash['category'] = Hash.new if @hash['category'].nil?
@hash['category'][id] = Category.new(@dbh, id) if @hash['category'][id].nil?
return @hash['category'][id]
when 'recipe'
raise "Invalid Record ID" if @dbh.select_one('select * from recipe where recipe_id=?', id).nil?
@hash['recipe'] = Hash.new if @hash['recipe'].nil?
@hash['recipe'][id] = Recipe.new(@dbh, id) if @hash['recipe'][id].nil?
return @hash['recipe'][id]
when 'ingredient'
raise "Invalid Record ID" if @dbh.select_one('select * from ingredient where ingredient_id=?', id).nil?
@hash['ingredient'] = Hash.new if @hash['ingredient'].nil?
@hash['ingredient'][id] = Ingredient.new(@dbh, id) if @hash['ingredient'][id].nil?
return @hash['ingredient'][id]
when 'food'
raise "Invalid Record ID" if @dbh.select_one('select * from food where food_id=?', id).nil?
@hash['food'] = Hash.new if @hash['food'].nil?
@hash['food'][id] = Food.new(@dbh, id) if @hash['food'][id].nil?
return @hash['food'][id]
when 'measure'
raise "Invalid Record ID" if @dbh.select_one('select * from measure where measure_id=?', id).nil?
@hash['measure'] = Hash.new if @hash['measure'].nil?
@hash['measure'][id] = Measure.new(@dbh, id) if @hash['measure'][id].nil?
return @hash['measure'][id]
else raise "Invalid Record Type"
end
end