0
0
Fluttermobile~10 mins

SQLite with sqflite package in Flutter - Interactive Code Practice

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

Complete 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'
Adatabase.db
Bmy_db
C"my_db.db"
D"database"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the database name.
Using a name without the .db extension.
2fill in blank
medium

Complete 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'
Aname
Busername
Cuser_name
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different column name than 'name'.
Forgetting to specify the column type.
3fill in blank
hard

Fix 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'
A{'name': 'Alice'}
B['name', 'Alice']
C'name: Alice'
D('name', 'Alice')
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a map.
Not using quotes around keys.
4fill in blank
hard

Fill 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'
A"name = ?"
B"Bob"
C"name == ?"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' in the where clause.
Not using a placeholder '?' in the where clause.
5fill in blank
hard

Fill 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'
A{'name': 'Charlie'}
B"id = ?"
C1
D"name = ?"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong where clause.
Not passing the id in whereArgs.