- 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 - Introduction
Installation
SQLite3 can be integrated with Python using sqpte3 module, which was written by Gerhard Haring. It provides an SQL interface comppant with the DB-API 2.0 specification described by PEP 249. You do not need to install this module separately because it is shipped by default along with Python version 2.5.x onwards.
To use sqpte3 module, you must first create a connection object that represents the database and then optionally you can create a cursor object, which will help you in executing all the SQL statements.
Python sqpte3 module APIs
Following are important sqpte3 module routines, which can suffice your requirement to work with SQLite database from your Python program. If you are looking for a more sophisticated apppcation, then you can look into Python sqpte3 module s official documentation.
Sr.No. | API & Description |
---|---|
1 | sqpte3.connect(database [,timeout ,other optional arguments]) This API opens a connection to the SQLite database file. You can use ":memory:" to open a database connection to a database that resides in RAM instead of on disk. If database is opened successfully, it returns a connection object. |
2 | connection.cursor([cursorClass]) This routine creates a cursor which will be used throughout your database programming with Python. This method accepts a single optional parameter cursorClass. If suppped, this must be a custom cursor class that extends sqpte3.Cursor. |
3 | cursor.execute(sql [, optional parameters]) This routine executes an SQL statement. The SQL statement may be parameterized (i. e. placeholders instead of SQL pterals). The sqpte3 module supports two kinds of placeholders: question marks and named placeholders (named style). For example − cursor.execute("insert into people values (?, ?)", (who, age)) |
4 | connection.execute(sql [, optional parameters]) This routine is a shortcut of the above execute method provided by the cursor object and it creates an intermediate cursor object by calpng the cursor method, then calls the cursor s execute method with the parameters given. |
5 | cursor.executemany(sql, seq_of_parameters) This routine executes an SQL command against all parameter sequences or mappings found in the sequence sql. |
6 | connection.executemany(sql[, parameters]) This routine is a shortcut that creates an intermediate cursor object by calpng the cursor method, then calls the cursor.s executemany method with the parameters given. |
7 | cursor.executescript(sql_script) This routine executes multiple SQL statements at once provided in the form of script. It issues a COMMIT statement first, then executes the SQL script it gets as a parameter. All the SQL statements should be separated by a semi colon (;). |
8 | connection.executescript(sql_script) This routine is a shortcut that creates an intermediate cursor object by calpng the cursor method, then calls the cursor s executescript method with the parameters given. |
9 | connection.total_changes() This routine returns the total number of database rows that have been modified, inserted, or deleted since the database connection was opened. |
10 | connection.commit() This method commits the current transaction. If you don t call this method, anything you did since the last call to commit() is not visible from other database connections. |
11 | connection.rollback() This method rolls back any changes to the database since the last call to commit(). |
12 | connection.close() This method closes the database connection. Note that this does not automatically call commit(). If you just close your database connection without calpng commit() first, your changes will be lost! |
13 | cursor.fetchone() This method fetches the next row of a query result set, returning a single sequence, or None when no more data is available. |
14 | cursor.fetchmany([size = cursor.arraysize]) 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. |
15 | cursor.fetchall() This routine fetches all (remaining) rows of a query result, returning a pst. An empty pst is returned when no rows are available. |