|
This section contains the following topics: |
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/.
To connect to Ingres from Python using the Ingres Python DBI driver, you must build and install the driver. Instructions are included in the Ingres Python DBI Driver readme, available on http://www.ingres.com/downloads/prod-download-drivers.php.
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\lib (shared library).
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.
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()