Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a database named 'my_db.db'.
Flutter
final database = await openDatabase([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the database name.
Using a name without the .db extension.
✗ Incorrect
The openDatabase function requires the database file name as a string, so "my_db.db" is correct.
2fill in blank
mediumComplete the code to create a table named 'users' with columns 'id' and 'name'.
Flutter
await database.execute('CREATE TABLE users(id INTEGER PRIMARY KEY, [1] TEXT)');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different column name than 'name'.
Forgetting to specify the column type.
✗ Incorrect
The column name is 'name' as specified, so 'name TEXT' is correct.
3fill in blank
hardFix the error in the code to insert a user with name 'Alice'.
Flutter
await database.insert('users', [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a map.
Not using quotes around keys.
✗ Incorrect
The insert method expects a Map for the values, so {'name': 'Alice'} is correct.
4fill in blank
hardFill both blanks to query all users where name is 'Bob'.
Flutter
final List<Map<String, dynamic>> users = await database.query('users', where: [1], whereArgs: [[2]]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' in the where clause.
Not using a placeholder '?' in the where clause.
✗ Incorrect
The where clause uses a placeholder '?', so "name = ?" is correct. The argument should be the string "Bob".
5fill in blank
hardFill all three blanks to update the name of user with id 1 to 'Charlie'.
Flutter
await database.update('users', [1], where: [2], whereArgs: [[3]]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong where clause.
Not passing the id in whereArgs.
✗ Incorrect
The update method needs a map of new values, a where clause with placeholder, and the id value in whereArgs.