Parameterised INSERT with commit
Adds a new record using ? placeholders filled safely from a tuple of values. The new row is only saved to the database file once conn.commit() is called.
Understanding Parameterised INSERT with commit in QCE Digital Solutions Unit 2
What it does: Two columns are listed, two ? placeholders are used and the tuple has two values, so each value lines up with its column. The INSERT only queues the new row. The conn.commit() line that follows saves it to the database file. commit() is a method of the connection object (conn), not the cursor. The commit must come after the INSERT, otherwise there is nothing new to save yet. Values fill the placeholders in order. The first ? matches name and the second ? matches price. Without commit() the new row stays pending and is lost when the connection closes, so commit() makes the change permanent.
Common mistakes: execute() takes the SQL and ONE tuple of values. The values must be bundled as (n, p), not passed as separate arguments. There are three ? placeholders but only two columns and two values in the tuple. Each ? needs exactly one value, so it should be VALUES (?, ?).
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 337–409) and word search (Modules 234–409).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
cursor.execute("INSERT INTO products (name, price) VALUES (?, ?)", (n, p))Fill in the Blanks
Spot the Error
Student with a class code? Join your class →