Not all SQL commands return rows, and in fact, some essential SQL commands do not. If we INSERT a row or CREATE a TABLE we will not receive a row in response. To perform SQL commands that do not return rows, we use db.run() to run the command. db.run() does not return a value, but, depending on the SQL command, it may attach properties to the this keyword within the scope of the callback. In some cases, like creating a table, db.run() will not modify this. In other cases, like when INSERTing a row, a callback to db.run() will be able to access this.lastID, the ID of the last INSERTed row.



Write a db.run() command that will INSERT the given data into our TemperatureData table. Be sure to use sqlite3 placeholders and not hard-code the values from newRow.

Add a function callback with a single argument and leave it empty for now. Make sure that this function is not an arrow.

See the hint for a reminder about the SQL INSERT syntax.


In a callback of db.run(), log this.lastID to see the id of the inserted row.


Notice that the logged value is undefined. What went wrong? Move on to the next exercise to find out.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?