PCPP1 practice question 4 of 10

Select the true statements about the sqirte3 module. (Select two answers.)

Full set: 45 questions
Answer options
A: The sqlite3 module provides an interface compliant with the DB-API 2.0. Correct answer
B: The special name memory is used to create a database in RAM.
C: The sqhte3 module does not support transactions.
D: The fetchall method returns an empty list when no rows are available Correct answer
Correct Answer:
A. The sqlite3 module provides an interface compliant with the DB-API 2.0.; D. The fetchall method returns an empty list when no rows are available
Explanation

The sqlite3 module is Python's built-in interface for the SQLite database engine. It is designed to be compliant with the Python Database API Specification 2.0 (PEP 249), which standardizes how Python programs interact with databases. This compliance ensures a consistent API for developers. As part of this specification, the cursor.fetchall() method is required to fetch all remaining rows from a query result. If the query yields no rows, or all rows have already been fetched, the method correctly returns an empty list ([]), providing a predictable way to handle empty result sets.

Why Incorrect

B. The special filename required to create an in-memory SQLite database is the string ":memory:", not "memory". The leading colon is mandatory.
C. The sqlite3 module fully supports database transactions through the Connection object's commit() and rollback() methods, which are essential for ensuring data integrity.

References

1. Python 3 Documentation, sqlite3 — DB-API 2.0 interface for SQLite databases.

For A: Section 13.13, Introduction. "This module provides a DB-API 2.0 compliant interface to the SQLite database."

For B: Section 13.13.2.1, sqlite3.connect(). "To use the database in RAM, specify :memory: for database."

For C: Section 13.13.3.2, Connection.commit(). This documents the method for committing the current transaction, confirming transaction support.

For D: Section 13.13.4.5, Cursor.fetchall(). The description states it "fetches all (remaining) rows of a query result, returning a list." This implies an empty list if no rows are available.

2. PEP 249 -- Python Database API Specification v2.0.

For A: Section "Introduction". The entire document specifies the interface that modules like sqlite3 implement.

For D: Section "Cursor Objects", .fetchall(). "Fetch all (remaining) rows of a query result, returning them as a sequence of sequences... An empty sequence is returned when no rows are available."

Scroll to Top