What's new? | Help | Directory | Sign in
Google
ibm-db
Python support for IBM Data Servers: DB2 and Informix IDS
  
  
  
  
    
Search
for
Updated May 08, 2008 by open...@us.ibm.com
Labels: Featured, Phase-Deploy
README  

Quick Getting Started Steps (README)

Install IBM_DB support for SQLAlchemy

The IBM_DB_SA adapter provides the Python/SQLAlchemy interface to IBM Data Servers. The implementation conforms to SQLAlchemy 0.4.0 specification.

The IBM_DB_SA adapter is packaged as a Python Egg component and is dependent on:

Installation and configuration

To install the IBM_DB_SA Python egg component (.egg), use the standard setuptools provided by the Python Easy Install, which is available through the Python Enterprise Application Kit community portal.

After installing Easy Install, perform these additional steps to install the IBM_DB_SA egg component:

Quick Sanity Test Example

IBM_DB SA adapter sanity test

$ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> from sqlalchemy import *
>>> import ibm_db_sa.ibm_db_sa
>>> db2 = sqlalchemy.create_engine('ibm_db_sa://db2inst1:secret@host.name.com:50000/pydev')
>>> metadata = MetaData()
>>> users = Table('users', metadata, 
    Column('user_id', Integer, primary_key = True),
    Column('user_name', String(16), nullable = False),
    Column('email_address', String(60), key='email'),
    Column('password', String(20), nullable = False)
)
>>> metadata.bind = db2
>>> metadata.create_all()
>>> users_table = Table('users', metadata, autoload=True, autoload_with=db2)
>>> users_table

IBM_DB DB-API wrapper sanity test

$ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
>>> ibm_db_conn = ibm_db.connect('pydev', 'db2inst1', 'secret')
>>> import ibm_db_dbi
>>> conn = ibm_db_dbi.Connection(ibm_db_conn)
>>> conn.tables('SYSCAT', '%')

Example: Using the Data Source Name (DSN) through CLI configuration

$ cat ./clidriver/db2cli.ini
...
[pydb]
Database=pydev
Protocol=tcpip
Hostname=host.name.com
Servicename=50000
uid=db2inst1
pwd=secret
$ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> from sqlalchemy import *
>>> import ibm_db_sa.ibm_db_sa
>>> db2 = sqlalchemy.create_engine('ibm_db_sa:///pydb?UID=db2inst1')
>>> ...
>>> db2 = sqlalchemy.create_engine('ibm_db_sa:///?DSN=pydb;UID=db2inst1')
>>> ...

Tested operating systems

Supported databases

Future supported databases

Feedback

Your feedback is very much appreciated and expected through project ibm-db: