Skip to content
Automatically exported from code.google.com/p/ibm-db
Python C
Branch: master
Clone or download
abhi7436 and SabaKauser fix for Blob data not inserted from ibm_db_sa orm (#408)
* fix for Blob data not inserted from ibm_db_sa orm

* updated if to elif

modified if condition check.
Latest commit bb24a0e Aug 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
IBM_DB fix for Blob data not inserted from ibm_db_sa orm (#408) Aug 21, 2019
contributing
.appveyor.yml Add Appveyor support for Windows CI (#346) Oct 1, 2018
.project Initial source code release to Google Code repository: Feb 9, 2008
.travis.yml add email address Sep 28, 2018
README.md Update README.md Apr 26, 2019

README.md

Python support for IBM DB2 and IBM Informix

Build Status

Python, DB-API components for IBM DB2 and Informix

Provides Python interface for connecting to IBM DB2 and Informix

Table of contents

Components

Pre-requisites

Installation

Quick Example

API Documentation

Downloads

Latest Updates

Support & Feedback

Contributing to the ibm_db python project

Components

  1. The ibm_db contains:
    • ibm_db driver: Python driver for IBM DB2 and IBM Informix databases. Uses the IBM Data Server Driver for ODBC and CLI APIs to connect to IBM DB2 and Informix.
    • ibm_db_dbi: Python driver for IBM DB2 and IBM Informix databases that complies to the DB-API 2.0 specification. Checkout the README for getting started with ibm_db and ibm_db_dbi

Pre-requisites

Install Python 2.7 or newer versions except python 3.3. Python ibm_db driver does not include support python 3.3 as it has reached end-of-life. You might need zlib, openssl, pip installations if not already available in your setup.

  • Linux/Unix: If you face problems due to missing python header files while installing the driver, you would need to install python developer package and retry install. e.g:
    zypper install python-devel
     or
    yum install python-devel

Installation

  • MAC OS: You can install the driver using pip as:
pip install --no-cache-dir ibm_db
  • All other platforms: You can install the driver using pip as:
pip install ibm_db

This will install ibm_db and ibm_db_dbi module.

The ODBC and CLI Driver(clidriver) is automatically downloaded at the time of installation and it is recommended to use this driver. However, if you wish to use an existing installation of clidriver or install the clidriver manually and use it, you can set IBM_DB_HOME environment variable. For more information on how to set this variable, refer Environment Variables section.

  • Environment Variables: IBM_DB_HOME :

    Set this environment variable to avoid automatic downloading of the clidriver during installation. You could set this to the installation path of ODBC and CLI driver in your environment. e.g:

    Windows :
    set IBM_DB_HOME=c:/Users/skauser/clidriver
    
    Other platforms:
    export IBM_DB_HOME=/home/skauser/clidriver
    

    The ODBC and CLI driver is available for download at Db2 LUW ODBC and CLI Driver. Refer to (License requirements) for more details on the CLI driver for manual download and installation.

Quick Example

$ python
Python 3.6.5 (default, May 10 2018, 00:54:55)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
>>> #For connecting to local database named pydev for user db2inst1 and password secret, use below example
>>> #ibm_db_conn = ibm_db.connect('pydev', 'db2inst1', 'secret')
>>> #For connecting to remote database named pydev for uid db2inst and pwd secret on host host.test.com, use below example
>>> # Connect using ibm_db
>>> conn_str='database=pydev;hostname=host.test.com;port=portno;protocol=tcpip;uid=db2inst1;pwd=secret'
>>> ibm_db_conn = ibm_db.connect(conn_str,'','')
>>>
>>> # Connect using ibm_db_dbi
>>> import ibm_db_dbi
>>> conn = ibm_db_dbi.Connection(ibm_db_conn)
>>> # Execute tables API
>>> conn.tables('DB2ADMIN', '%')
[{'TABLE_CAT': None, 'TABLE_SCHEM': 'DB2ADMIN', 'TABLE_NAME': 'MYTABLE', 'TABLE_TYPE': 'TABLE', 'REMARKS': None}]
>>>
>>> # create table using ibm_db
>>> create="create table mytable(id int, name varchar(50))"
>>> ibm_db.exec_immediate(ibm_db_conn, create)
<ibm_db.IBM_DBStatement object at 0x7fcc5f44f650>
>>>
>>> # Insert 3 rows into the table
>>> insert = "insert into mytable values(?,?)"
>>> params=((1,'Sanders'),(2,'Pernal'),(3,'OBrien'))
>>> stmt_insert = ibm_db.prepare(ibm_db_conn, insert)
>>> ibm_db.execute_many(stmt_insert,params)
3
>>> # Fetch data using ibm_db_dbi
>>> select="select id, name from mytable"
>>> cur = conn.cursor()
>>> cur.execute(select)
True
>>> row=cur.fetchall()
>>> print("{} \t {} \t {}".format(row[0],row[1],row[2]),end="\n")
(1, 'Sanders')   (2, 'Pernal')   (3, 'OBrien')
>>> row=cur.fetchall()
>>> print(row)
[]
>>>
>>> # Fetch data using ibm_db
>>> stmt_select = ibm_db.exec_immediate(ibm_db_conn, select)
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print("%s, %s" % (cols[0], cols[1]))
1, Sanders
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print("%s, %s" % (cols[0], cols[1]))
2, Pernal
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print("%s, %s" % (cols[0], cols[1]))
3, OBrien
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print(cols)
False
>>>
>>> # Close connections
>>> cur.close()
True
>>> ibm_db.close(ibm_db_conn)
True

More examples can be found under 'tests' folder.

API Documentation

For more information on the APIs supported by ibm_db, please refer to below link:

https://github.com/ibmdb/python-ibmdb/wiki/APIs

License requirements for connecting to databases

Python ibm_db driver can connect to DB2 on Linux Unix and Windows without any additional license/s, however, connecting to databases on DB2 for z/OS or DB2 for i(AS400) Servers require either client side or server side license/s. The client side license would need to be copied under license folder of your cidriver installation directory and for activating server side license, you would need to purchase DB2 Connect Unlimited for System z® and DB2 Connect Unlimited Edition for System i®.

To know more about license and purchasing cost, please contact IBM Customer Support.

To know more about server based licensing viz db2connectactivate, follow below links:

If you intend to install the clidriver manually, Following are the details of the client driver versions that you can download from CLIDRIVER to be able to connect to databases on non-LUW servers. You would need the client side license file as per Version for corresponding installation.:

CLIDriver and Client license versions for Specific Platform and Architecture

Platform Architecture Cli Driver Supported Version
AIX ppc aix32_odbc_cli.tar.gz Yes V11.1
others aix64_odbc_cli.tar.gz Yes V11.1
Darwin x64 macos64_odbc_cli.tar.gz Yes V10.5
Linux x64 linuxx64_odbc_cli.tar.gz Yes V11.1
s390x s390x64_odbc_cli.tar.gz Yes V11.1
s390 s390_odbc_cli.tar.gz Yes V11.1
ppc64 (LE) ppc64le_odbc_cli.tar.gz Yes V11.1
ppc64 ppc64_odbc_cli.tar.gz Yes V10.5
ppc32 ppc32_odbc_cli.tar.gz Yes V10.5
others linuxia32_odbc_cli.tar.gz Yes V11.1
Windows x64 ntx64_odbc_cli.zip Yes V11.1
x32 nt32_odbc_cli.zip Deprecated NA
Sun i86pc sunamd64_odbc_cli.tar.gz Yes V10.5
sunamd32_odbc_cli.tar.gz Yes V10.5
sparc sun64_odbc_cli.tar.gz Yes V11.1
sparc sun32_odbc_cli.tar.gz Yes V11.1

You can refer to ODBC and CLI Driver installation for details on how to install the driver manually.

Downloads

Use following pypi web location for downloading source code and binaries ibm_db: https://pypi.python.org/pypi/ibm_db . You can also get the source code by cloning the ibm_db github repository as :

git clone git@github.com:ibmdb/python-ibmdb.git

Latest Updates

Updated ibm_db

Mar 14th 2019: A new release 3.0.1 of ibm_db and ibm_db_dbi available.

Support & feedback

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

Contributing to the ibm_db python project

See CONTRIBUTING

The developer sign-off should include the reference to the DCO in remarks(example below):
DCO 1.1 Signed-off-by: Random J Developer <random@developer.org>
You can’t perform that action at this time.