It is a library that allows you to use a lightweight SQL database (SQLite) inside your React Native app to store and manage data locally on the device.
Click to reveal answer
beginner
How do you open or create a database using expo-sqlite?
You use SQLite.openDatabase('name.db') which opens the database if it exists or creates it if it doesn't.
Click to reveal answer
intermediate
What method is used to run SQL commands like creating tables or inserting data?
You use db.transaction(tx => { tx.executeSql(sql, params, success, error) }) to run SQL commands inside a transaction.
Click to reveal answer
intermediate
Why do we use transactions when working with expo-sqlite?
Transactions ensure that a group of SQL commands run safely together. If one command fails, the whole transaction can be rolled back to keep data consistent.
Click to reveal answer
intermediate
How can you retrieve data from the database using expo-sqlite?
Inside a transaction, use executeSql with a SELECT query. The results are in the resultSet.rows._array property inside the success callback.
Click to reveal answer
Which function opens or creates a SQLite database in expo-sqlite?
ASQLite.openDatabase('mydb.db')
BSQLite.createDatabase('mydb.db')
CSQLite.connect('mydb.db')
DSQLite.initDatabase('mydb.db')
✗ Incorrect
The correct method to open or create a database is SQLite.openDatabase('mydb.db').
What is the purpose of the transaction method in expo-sqlite?
ATo open the database connection
BTo backup the database
CTo close the database
DTo run multiple SQL commands safely as a group
✗ Incorrect
Transactions group SQL commands so they run safely together, ensuring data integrity.
Where do you find the rows returned by a SELECT query in expo-sqlite?
AresultSet.records
BresultSet.rows._array
CresultSet.rowsArray
DresultSet.data
✗ Incorrect
The rows returned are inside resultSet.rows._array in the success callback.
Which SQL command creates a new table in expo-sqlite?
ACREATE TABLE IF NOT EXISTS tablename (...)
BNEW TABLE tablename (...)
CMAKE TABLE tablename (...)
DADD TABLE tablename (...)
✗ Incorrect
The correct SQL syntax to create a table if it doesn't exist is CREATE TABLE IF NOT EXISTS.
What happens if one SQL command fails inside a transaction?
AThe database closes automatically
BOnly the failed command is ignored, others continue
CThe whole transaction rolls back and no changes are saved
DThe app crashes
✗ Incorrect
Transactions ensure all commands succeed or none do, so failure rolls back all changes.
Explain how to create a simple table and insert data using expo-sqlite in React Native.
Think about opening the database, then running SQL commands inside a transaction.
You got /5 concepts.
Describe how to retrieve and display data from a SQLite database using expo-sqlite.
Focus on running a SELECT query and accessing the results in the callback.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using expo-sqlite in a React Native app?
easy
A. To store and manage data locally using a small database
B. To fetch data from a remote server
C. To style the app interface
D. To handle user authentication
Solution
Step 1: Understand expo-sqlite functionality
expo-sqlite provides a way to store data locally on the device using a SQLite database.
Step 2: Compare options with expo-sqlite purpose
Only To store and manage data locally using a small database describes local data storage with a database, which matches expo-sqlite's role.
Final Answer:
To store and manage data locally using a small database -> Option A
Quick Check:
expo-sqlite = local database storage [OK]
Hint: expo-sqlite is for local data storage, not remote or styling [OK]
Common Mistakes:
Confusing expo-sqlite with network data fetching
Thinking expo-sqlite handles UI styling
Assuming expo-sqlite manages user login
2. Which of the following is the correct way to open a database using expo-sqlite?
A. The SQL statement has fewer values than placeholders
B. The table name is incorrect
C. The transaction method is missing a callback
D. The executeSql method cannot use placeholders
Solution
Step 1: Check SQL placeholders and values
The SQL has two placeholders (?, ?) but only one value 'John' is provided.
Step 2: Identify mismatch causing error
Mismatch between placeholders and values causes an error during execution.
Final Answer:
The SQL statement has fewer values than placeholders -> Option A
Quick Check:
Placeholders must match values count [OK]
Hint: Match number of ? placeholders with values array length [OK]
Common Mistakes:
Ignoring mismatch between placeholders and values
Assuming table name is wrong without checking
Thinking executeSql cannot use placeholders
5. You want to display a list of items stored in a SQLite table inside your React Native app. Which approach correctly updates the UI after fetching data from the database?
const [items, setItems] = useState([]);
useEffect(() => {
db.transaction(tx => {
tx.executeSql('SELECT * FROM items;', [], (_, { rows }) => {
// What should go here?
});
});
}, []);
hard
A. items = rows._array;
B. return rows._array;
C. setItems(rows._array);
D. console.log(rows._array);
Solution
Step 1: Understand React state update
To update UI, React state setter setItems must be called with new data.
Step 2: Identify correct way to update state
Assigning directly to items or returning data won't update state; logging only shows data.
Final Answer:
setItems(rows._array); -> Option C
Quick Check:
Use setItems() to update state and UI [OK]
Hint: Use setState function to update React state after DB fetch [OK]
Common Mistakes:
Assigning directly to state variable instead of using setter
Returning data inside executeSql callback
Only logging data without updating state
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.