The script from the command line, should it save example.db file in the same directory?
Where is the example.db file?
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS food_db
(item, calories, total fat, protein)''')
conn.commit()
food_items = [ ('Broccoli Chinese', 22, 0.7, 1.1),
('chia seeds', 490, 30.8, 15.6),
('blueberries', 57, 0.3, 0.7),]
c.executemany('INSERT INTO food_db VALUES (?,?,?,?)',food_items)
for row in c.execute('SELECT * FROM food_db ORDER BY calories'):
print(row)
conn.close()
This script is in the same directory
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
for row in c.execute('SELECT * FROM food_db ORDER BY calories'):
print(row)
Run on the command line, nothing gets returned, no error, just nothing. Why does it not return the rows that the database should contain?
Edit: ok looks like i just needed a
conn.commit()
after i inserted into the table to save it then it returns also with the second script.
but my first questions still remains, where is the example.db file?