Assert Student Sqlite Query Matches Expected Results
Validate if the student's sqlite query matches the expected query
Location of the snippet: databases/sqlite/assert_student_sqlite_query_matches_expected_results
This snippet is used to validate if the student's sqlite query matches the expected query.
| Device Type |
|---|
| On-device |
Variables:
| Variable Name | Variable Description | Type | Required? | Default |
|---|---|---|---|---|
correct_query | The correct query | str | Yes | |
db_file_name | The name of the sqlite database file | str | Yes | |
sqlite_base_path | The path to the sqlite database file | str | Yes | |
conn_kwargs | ADVANCED. Leave empty. Should be a literal dictionary that will be parsed in the execution environment | dict | No |
Examples:
1. Basic SELECT Query Validation
This example checks if the student's query correctly selects all data from a specific table in a provided SQLite database file.
Scenario: Students are given an inventory.db SQLite database and need to retrieve all records from the products table.
Pre-requisite (for the environment/instructor):
An inventory.db file exists at /data/sqlite_dbs/ with a products table.
Solution:
SELECT * FROM products;
Snippet for the assertion:
| Variable Name | Value |
|---|---|
correct_query | SELECT * FROM products; |
db_file_name | inventory.db |
sqlite_base_path | /data/sqlite_dbs/ |
2. SELECT with WHERE Clause and Specific Columns
This example validates a query that filters data and selects only specific columns from a table.
Scenario: Students need to find the name and price of products with a category of 'Electronics' from the products table in inventory.db.
Pre-requisite (for the environment/instructor):
An inventory.db file exists at /data/sqlite_dbs/ with a products table containing 'name', 'price', and 'category' columns.
Solution:
SELECT name, price FROM products WHERE category = 'Electronics';
Snippet for the assertion:
| Variable Name | Value |
|---|---|
correct_query | SELECT name, price FROM products WHERE category = 'Electronics'; |
db_file_name | inventory.db |
sqlite_base_path | /data/sqlite_dbs/ |