Skip to main content

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 NameVariable DescriptionTypeRequired?Default
correct_queryThe correct querystrYes
db_file_nameThe name of the sqlite database filestrYes
sqlite_base_pathThe path to the sqlite database filestrYes
conn_kwargsADVANCED. Leave empty. Should be a literal dictionary that will be parsed in the execution environmentdictNo

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 NameValue
correct_querySELECT * FROM products;
db_file_nameinventory.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 NameValue
correct_querySELECT name, price FROM products WHERE category = 'Electronics';
db_file_nameinventory.db
sqlite_base_path/data/sqlite_dbs/