So far we’ve managed to:
That’s pretty significant! Now it’s time to take that useful information and add it to a table of our own. Since creating a table is another operation that does not return a row, we can use the same
db.run() we used to
INSERT rows. Let’s see what happens when we
INSERT our data into it.
Notice there’s a statement declaring “DROP TABLE IF EXISTS” — this is because we want to make sure when we create our new table that we won’t run into an error telling us the table already exists (from previous times running our code).
CREATE a new table
id: INTEGER PRIMARY KEY year: INTEGER NOT NULL temperature: REAL NOT NULL
After creating your table with
db.run(), iterate through your
averageTemperatureByYear array and
INSERT each into your table using a
It looks like an error was thrown. Add a callback after your
INSERT query in
db.run() and log the error to the console if it exists.
We’ve triggered a lot of errors! It looks like some
INSERTs are happening before the table has been created. Click ‘Next’ to find out why this is happening and how to fix it.