Hello
Did anyone use 'ibm_db' package of i-series/python to update DB2 files in AS400 ??
I want to use Python scripts(from QSH) to update 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 class variables and have got values.
TYPE, DRPARTY, CRPARTY etc are fields of TEMPPF
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 couple of formats available in the internet, either they are not compatible with Python, or they are not good examples.
Pls help.
Regards, Dipayan
Did anyone use 'ibm_db' package of i-series/python to update DB2 files in AS400 ??
I want to use Python scripts(from QSH) to update 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 class variables and have got values.
TYPE, DRPARTY, CRPARTY etc are fields of TEMPPF
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 couple of formats available in the internet, either they are not compatible with Python, or they are not good examples.
Pls help.
Regards, Dipayan
Comment