0
0
Raspberry Piprogramming~10 mins

SQLite database for sensor data in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SQLite library.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Asys
Bos
Csqlite3
Drandom
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like os or sys.
2fill in blank
medium

Complete the code to connect to a database file named 'sensor_data.db'.

Raspberry Pi
conn = sqlite3.[1]('sensor_data.db')
Drag options to blanks, or click blank then click option'
Aconnect
Bopen
Cstart
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using open or create which are not SQLite connection methods.
3fill in blank
hard

Fix the error in the SQL command to create a table named 'readings' with columns 'id' (integer primary key) and 'value' (real).

Raspberry Pi
cursor.execute('CREATE TABLE [1] (id INTEGER PRIMARY KEY, value REAL)')
Drag options to blanks, or click blank then click option'
Areadings
Bdata
Csensor
Dvalues
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect table names like 'data' or 'sensor'.
4fill in blank
hard

Fill both blanks to insert a sensor value into the 'readings' table using a parameterized query.

Raspberry Pi
cursor.execute('INSERT INTO readings (value) VALUES ([1])', ([2],))
Drag options to blanks, or click blank then click option'
A?
Bsensor_value
C:value
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using literal values instead of placeholders.
Using incorrect variable names.
5fill in blank
hard

Fill all three blanks to commit the transaction, close the cursor, and close the connection.

Raspberry Pi
conn.[1]()
cursor.[2]()
conn.[3]()
Drag options to blanks, or click blank then click option'
Arollback
Bclose
Ccommit
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using rollback instead of commit.
Forgetting to close cursor or connection.