- Python Data Access - Discussion
- Python Data Access - Useful Resources
- Python Data Access - Quick Guide
- Python MongoDB - Limit
- Python MongoDB - Update
- Python MongoDB - Drop Collection
- Python MongoDB - Delete Document
- Python MongoDB - Sort
- Python MongoDB - Query
- Python MongoDB - Find
- Python MongoDB - Insert Document
- Python MongoDB - Create Collection
- Python MongoDB - Create Database
- Python MongoDB - Introduction
- Python SQLite - Cursor Object
- Python SQLite - Join
- Python SQLite - Limit
- Python SQLite - Drop Table
- Python SQLite - Delete Data
- Python SQLite - Update Table
- Python SQLite - Order By
- Python SQLite - Where Clause
- Python SQLite - Select Data
- Python SQLite - Insert Data
- Python SQLite - Create Table
- Python SQLite - Establishing Connection
- Python SQLite - Introduction
- Python PostgreSQL - Cursor Object
- Python PostgreSQL - Join
- Python PostgreSQL - Limit
- Python PostgreSQL - Drop Table
- Python PostgreSQL - Delete Data
- Python PostgreSQL - Update Table
- Python PostgreSQL - Order By
- Python PostgreSQL - Where Clause
- Python PostgreSQL - Select Data
- Python PostgreSQL - Insert Data
- Python PostgreSQL - Create Table
- Python PostgreSQL - Create Database
- Python PostgreSQL - Database Connection
- Python PostgreSQL - Introduction
- Python MySQL - Cursor Object
- Python MySQL - Join
- Python MySQL - Limit
- Python MySQL - Drop Table
- Python MySQL - Delete Data
- Python MySQL - Update Table
- Python MySQL - Order By
- Python MySQL - Where Clause
- Python MySQL - Select Data
- Python MySQL - Insert Data
- Python MySQL - Create Table
- Python MySQL - Create Database
- Python MySQL - Database Connection
- Python MySQL - Introduction
- Python Data Access - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python SQLite - Cursor Object
The sqpte3.Cursor class is an instance using which you can invoke methods that execute SQLite statements, fetch data from the result sets of the queries. You can create Cursor object using the cursor() method of the Connection object/class.
Example
import sqpte3 #Connecting to sqpte conn = sqpte3.connect( example.db ) #Creating a cursor object using the cursor() method cursor = conn.cursor()
Methods
Following are the various methods provided by the Cursor class/object.
Sr.No | Method & Description |
---|---|
1 | execute() This routine executes an SQL statement. The SQL statement may be parameterized (i.e., placeholders instead of SQL pterals). The psycopg2 module supports placeholder using %s sign For example:cursor.execute("insert into people values (%s, %s)", (who, age)) |
2 | executemany() This routine executes an SQL command against all parameter sequences or mappings found in the sequence sql. |
3 | fetchone() This method fetches the next row of a query result set, returning a single sequence, or None when no more data is available. |
4 | fetchmany() This routine fetches the next set of rows of a query result, returning a pst. An empty pst is returned when no more rows are available. The method tries to fetch as many rows as indicated by the size parameter. |
5 | fetchall() This routine fetches all (remaining) rows of a query result, returning a pst. An empty pst is returned when no rows are available. |
Properties
Following are the properties of the Cursor class −
Sr.No | Method & Description |
---|---|
1 | arraySize This is a read/write property you can set the number of rows returned by the fetchmany() method. |
2 | description This is a read only property which returns the pst containing the description of columns in a result-set. |
3 | lastrowid This is a read only property, if there are any auto-incremented columns in the table, this returns the value generated for that column in the last INSERT or, UPDATE operation. |
4 | rowcount This returns the number of rows returned/updated in case of SELECT and UPDATE operations. |
5 | connection This read-only attribute provides the SQLite database Connection used by the Cursor object. |