iSeriesPython

db2 Module

The db2 module implements the DB-API v2.0 specification.

  • connect([dsn, user, pwd, database, autocommit, sysnaming, severmode])
    Connection object
    All parameters are optional.
    • dsn, (default *local), data source name. Use the command dsprdbdire to list valid values.
    • database, (default user), default library.(not valid with sysnaming)
    • autocommit, (default False). Statements are committed when executed. Set this to True if files are not journaled.
    • sysnaming, (default False). System naming mode, use of *libl and / delimiter.
    • servermode, (default True). Run all statements in a server job.
  • The cursor supports iteration and the execute method returns self. (see examples)
  • The result from fetchxxx is a Row object.(implements the sequence protocol).
  • Stored procedures is not yet implemented.
  • Date and time types are returned as ISO formatted strings.
Examples:

import db2
c = db2.connect()
crs = c.cursor()
for r in crs.execute('select * from mylib.myfile'):
    print r
...
crs.execute('select * from mylib.myfile')
row = crs.fetchone()
print row
...
crs.execute('insert into mylib.myfile values(?, ?, ?), ('a',1,2))
c.commit()
...