1

I have this query executed with the following snippet:

cursor2.execute("UPDATE datatable SET data1 = ?, data2 = ?, data3 = ? WHERE id = ?",[d1,d2,d3,i])
print("affected rows = {}".format(cursor2.rowcount))

Affected rows returns 1 but row in database was not updated.

Printing the d1,d2,d3 is fine only the update in the database doesn't work.

Is there something wrong with the function?

Additional:

I tried this way:

sql_update_query = """UPDATE datatable SET data1 = %s, data2 = %s, data3 = %s WHERE id = %s"""
inputData = (d1,d2,d3,i)
cursor2.execute(sql_update_query, inputData)

But it retuns this error:

('HY000', 'The SQL contains 0 parameter markers, but 4 parameters were supplied')

Thanks for the help.

Marios
  • 26,333
  • 8
  • 32
  • 52
Rav
  • 1,327
  • 3
  • 18
  • 32
  • 1
    You may need to issue a `commit` somewhere. See https://stackoverflow.com/questions/20199569/pyodbc-insert-into-sql. –  Sep 17 '19 at 07:11

1 Answers1

1

Looks like you are missing .commit()

Ex:

cursor2.execute("UPDATE datatable SET data1 = ?, data2 = ?, data3 = ? WHERE id = ?",(d1,d2,d3,i))
cursor2.commit()
Rakesh
  • 81,458
  • 17
  • 76
  • 113