PCPP1 practice question 2 of 10
Select the true statements about the sqlite3 module. (Select two answers.)
Full set: 45 questionsThe Python sqlite3 module implements the DB-API 2.0 specification (PEP 249). In this API, database operations are performed using a Cursor object. The Cursor.execute() method is used to execute a single SQL statement. After executing a SELECT query, data is retrieved using fetch methods. The Cursor.fetchone() method retrieves the next available row from the result set. If no more rows are available to be fetched, it returns None, signaling the end of the result set.
A. The sqlite3.Cursor object does not have a method named fetchalt. The fetchall() method returns an empty list ([]), not None, when no rows are available.
B. The execute() method is designed to execute only one SQL statement at a time. For executing multiple statements, the non-standard executescript() method must be used.
1. Python 3 Documentation, sqlite3 — DB-API 2.0 interface for SQLite databases:
Section 13.13.4.2. Cursor Objects: States that Cursor.execute(sql[, parameters]) executes an SQL statement. This validates option C.
Section 13.13.4.2. Cursor Objects: Describes Cursor.fetchone() as: "Fetches the next row of a query result set, returning a single tuple, or None when no more data is available." This validates option D.
Section 13.13.4.2. Cursor Objects: Describes Cursor.fetchall() as: "Fetches all (remaining) rows of a query result, returning a list." This confirms an empty list is returned for no rows, invalidating the premise of option A.
Section 13.13.4.2. Cursor Objects: Describes Cursor.executescript() as the method for executing multiple SQL statements, which invalidates option B.
2. PEP 249 -- Python Database API Specification v2.0:
Cursor Objects Section: The specification mandates that cursor objects must have an execute() method, confirming option C.
fetchone() Method Description: The specification requires that fetchone() "return a single sequence, or None when no more data is available," which directly supports option D.
Keep practicing
Take the free PCPP1 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCPP1 practice questions
- Question 1Select the true statements about the connection-oriented and connectionless types of comm…
- Question 4Select the true statements about the sqirte3 module. (Select two answers.)
- Question 5If w is a correctly created main application window, which method would you use to foe bo…
- Question 7Select the true statements about the json.-dumps () function. (Select two answers.)
- Question 9Select the true statements related to PEP 8 naming conventions. (Select two answers.)
- Question 10Select the true statement related to PEP 257.
