Runner Bean
Runner Bean

Reputation: 5165

sqlite python - create new table by multiplying values from existing tables

which would look like

(u'24/8/2019', u'Broccoli Chinese', 33, 10.5, 1.65)
(u'24/8/2019',u'blueberries', 22.8, 1.3, 0.28)
(u'24/8/2019',u'chia seeds', 171.5, 10.75, 5.4)
(u'25/8/2019',u'blueberries', 45.6, 2.4, 0.56)

Is the some sort of SQLite hack to do this?

as a start ive tried

c.execute('''CREATE TABLE IF NOT EXISTS nutrition_consumed
                (date, item, calories, total fat, protein)''')

for row in c.execute('SELECT * FROM food_consumption'):
        item_nutritional_values = c.execute('SELECT calories, total fat, protein FROM nutritional_values WHERE item=?', row[1])
        print(item_nutritional_values)

this brings up the error

item_nutritional_values = c.execute('SELECT calories, total fat, protein FROM nutritional_values WHERE item=?', row[1])
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 16 supplied.

Upvotes: 0

Views: 71

Answers (1)

LinPy
LinPy

Reputation: 18578

you need to supply you row as a tuple:

item_nutritional_values = c.execute('SELECT calories, total fat, protein FROM nutritional_values WHERE item=?', (row[1],))

Upvotes: 1

Related Questions