Sqlite Cursor Class

Overview:

Generally a database cursor enables iterating over a recordset.

With the execute() method of the cursor class from sqlite3 module it is not just retrieval of data but any SQL command to

  • create a table
  • insert rows
  • delete rows
  • update rows
  • query rows
  • execute other database operations

can be run on a SQLite database through the cursor object.

Sqlite3 module through the class Cursor provides several methods for executing various SQL commands and DB operations.

 

List of methods provided by Cursor class of Sqlite3 module:

Method Name

Description

execute(sqlStatement, [parameters])

Executes an SQL statement on the SQLite database

executemany(sqlStatement, [parameters])

Executes an SQL statement on the SQLite database. The statement is executed ‘n’ number of times once for each parameter specified in the parameters

executescript(sqlScript)

Executes a SQL script. This is a non-standard way.

fetchmany(numRows=cursor.arraysize)

From a SQL query result, fetches the next set of rows as specified by the parameter numRows. The results are returned as python list object.

fetchall()

From a SQL query result, fetches all the rows. The results are returned as python list object.

close()

Closes the cursor object. Python will raise a ProgrammingError exception if any further operation is attempted on a closed cursor.


Copyright 2022 © pythontic.com