Running CRUD operations
CRUD is short for Create, Read, Update, Delete, which are the four essential operations that are run on any database.
Now that we have created tables to hold our temperature and humidity readings, let's run some basic operations on them to get the hang of SQLite and the SQL syntax.
Note
For the purpose of this chapter, only the temperature
table will be used, but the commands can be easily translated to be used on the humidity
table as well.
Create
We start by inserting a dummy value into our temperature
table:
INSERTINTO temperature VALUES(datetime('now'),16.7);
This is standard SQL syntax, where we direct SQLite to insert the current datetime
and dummy value of 16.7
into our temperature table. The order of values should be the same as the order of columns defined in our CREATE TABLE
statement from before.
The datetime
function is specific to SQLite. Based on its arguments, it returns the datetime in a number of formats. When we call this function with the argument of...