Has anyone used the ibm_db package with IBM's Python for PASE to update Db2 files on IBM i (formerly AS/400)?
I want to use Python scripts (from QSH) to update the Db2 database. My purpose is to populate values at runtime and update the fields of Db2 files. It works with static (hardcoded) values, but not dynamic ones.
Here is what I am trying, but it is not working:
import ibm_db
c1 = ibm_db.connect('*LOCAL','userid','password')
sql = """INSERT INTO TEMPLIB.TEMPPF (TYPE, DRPARTY, CRPARTY,
AMOUNT,ACNUM, DESCRIPT)
VALUES('%s', '%s', '%s', '%s', '%s', '%s'),
%(self.type, self.debitparty, self.creditparty, self.amount,
self.craccountnumber, self.description) with NC
"""
stmt = ibm_db.exec_immediate(c1, sql )
self.type,self.debitparty, etc. are Python instance variables and have values.TYPE,DRPARTY,CRPARTY, etc. are fields ofTEMPPF.
Something simpler like populating the 'sql' variable as below works:
sql = "select * from TEMPLIB.TEMPPF"
So somewhere I am not making the INSERT format correctly. Does anyone know the format please? I tried a couple of formats available on the Internet, but they are not compatible with Python, or they are not good examples.
ibm_dbat all, justibm_db_dbi. Then more-or-less just follow PEP 249.