sqliteHow do I use the sqlite fetchall method?
The sqlite fetchall method is used to retrieve all rows of a query result in a single call. It returns a list of tuples containing all the rows of the query result. The syntax of the fetchall method is as follows:
cursor.fetchall()The following example shows how to use the fetchall method to retrieve all the rows of a query result:
import sqlite3
conn = sqlite3.connect("mydatabase.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM employees")
rows = cursor.fetchall()
for row in rows:
    print(row)
# Output:
# (1, 'John', 'Doe', '[email protected]')
# (2, 'Jane', 'Doe', '[email protected]')The code above:
- Imports the sqlite3module.
- Creates a connection to the database.
- Creates a cursor object.
- Executes a query to select all rows from the employeestable.
- Calls the fetchall()method to retrieve all rows of the query result.
- Iterates over the rows and prints them.
Helpful links
More of Sqlite
- How do I use UUIDs in SQLite?
- How do I use SQLite xfilter to filter data?
- How can I use SQLite with Xamarin Forms?
- How can I adjust the text size in SQLite?
- How do I use the SQLite Workbench?
- How do I show the databases in SQLite?
- How do I use SQLite with Visual Studio?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I call sqlitepcl.raw.setprovider() when using SQLite?
- How do I use the SQLite VARCHAR data type?
See more codes...