Connecting to Ingres from Python

This section contains the following topics:

Requirements

Ingres Python DBI Driver and the Ingres ODBC Driver

Create a Connection to Ingres

Example—Connect to Ingres and Select from a Table

Previous Topic

Next Topic

Requirements

To connect to Ingres from Python, you must meet the following prerequisites:

You can download the latest version of Python from http://www.python.org/.

Previous Topic

Next Topic

Ingres Python DBI Driver and the Ingres ODBC Driver

To connect to Ingres from Python using the Ingres Python DBI driver, you can use pre-built binaries, which you can download from http://www.ingres.com/downloads/prod-download-drivers.php. The version of the binary driver depends on the version of Python installed. For more information on version compatibility, see the Ingres Python DBI Driver readme.

The Ingres Python DBI driver requires that you have installed Ingres and the Ingres ODBC driver. For more information about the Ingres ODBC driver, see the chapter "Understanding ODBC Connectivity" in the Connectivity Guide. The Ingres ODBC driver is located in the following Ingres directory: ingres\bin (DLL).

Previous Topic

Next Topic

Create a Connection to Ingres

To connect to Ingres, you must instantiate an instance of the Connection class using the ingresdbi.connect() function.

If you have created a DSN, you could use the following code:

conn = ingresdbi.connect(dsn="myDSN")

Or you could connect directly to an Ingres database:

conn = ingresdbi.connect(database="myDB")

The ingresdbi.connect() function has other keywords that you can specify. For complete information, see the Ingres Python DBI Driver readme.

Previous Topic

Next Topic

Example—Connect to Ingres and Select from a Table

The following is a simple segment of code that connects to the Ingres database iidbdb and selects from iitables.

import ingresdbi

conn = ingresdbi.connect(database='iidbdb')

curs = conn.cursor()

curs.execute('select table_owner, table_name from iitables')

for x in curs:

     print x

curs.close()

conn.close()


© 2007 Ingres Corporation. All rights reserved.