1

I am trying to execute a prepared statement to a db2 on IBM Cloud. I only want to run the query if a data_array is populated which I have controlled that it is. This is my code:

conn = ibm_db.connect(dsn, "", "")
ibm_db.autocommit(conn, ibm_db.SQL_AUTOCOMMIT_OFF)

ins_sql = "insert into MY_TABLE (ID, NAME) values (?, ?)"
ins_stm = ibm_db.prepare(conn, ins_sql)

if data_array:
    for data in data_array:
        ibm_db.bind_param(ins_stm, 1, data['ID'])
        ibm_db.bind_param(ins_stm, 2, data['NAME'])
        ibm_db.execute(ins_stm)

    ibm_db.commit(conn)

When I run it I get the following error in the ibm_db.execute(ins_stm)-line.

Exception: Binding Error 3: [IBM][CLI Driver] CLI0102E Invalid conversion. SQLSTATE=07006 SQLCODE=-99999

What am I doing wrong here?

data_henrik
  • 16,724
  • 2
  • 28
  • 49
jawwe
  • 638
  • 1
  • 5
  • 13
  • You have `data` and `event`...?! – data_henrik Jun 25 '18 at 13:53
  • 1
    Edit your question to give the Db2-server details (operating-system, Db2 version) and the encoding for the database. Old Db2-LUW versions sometimes threw this exception when source data was variable width UTF-8 but target column/table/tablespace encoding was fixed-width, long since fixed. – mao Jun 25 '18 at 14:24

1 Answers1

0

My guess is that it is a copy & paste error. You have data in the array, but use event to get the array part. Change that to data['ID'] etc.

data_henrik
  • 16,724
  • 2
  • 28
  • 49