0

I have some python code that looks like this

import pypyodbc
import pandas as pd
home="c:/SQL/"
df = pd.read_sql_query(sql4, conn3
for y1 in range(0 , k):
    ARCHIVE_SERNUM = (df['sernum']).iloc[y1]
    KQL=len(KIC53_QUERY_LIST)
    FOUND=False
    for y2 in range(0,KQL):
        if ARCHIVE_SERNUM == KIC53_QUERY_LIST[y2]:
            FOUND=True
            #do something then
            break
    if FOUND == False:
        print(FOUND,ARCHIVE_SERNUM,"This is STIME : ",STIME)
        CTIME=STIME
        cursor = conn3.cursor()
        cursor.execute("""
            UPDATE ENCOMPASS_DIA
            SET CTIME=%s
            WHERE SERNUM=ARCHIVE_SERNUM
            """, (STIME))

Its throwing an error and I cannot figure out what is going on. In this example both CTIME and STIME are equal to the same 17 character string.

File "c:/SQL/ConnectionTest8.py", line 212, in <module>
""", (STIME))

TypeError: Params must be in a list, tuple, or Row
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
C0ppert0p
  • 634
  • 2
  • 7
  • 23

2 Answers2

1

An easy enough mistake to make.

 cursor.execute("""
        UPDATE ENCOMPASS_DIA
        SET CTIME=%s
        WHERE SERNUM=ARCHIVE_SERNUM
        """, (STIME, ))

There should be a trailing , after the STIME or (STIME) will be interpreted as a list instead of a tuple.

e4c5
  • 52,766
  • 11
  • 101
  • 134
  • does the fact I'm using an access DB make a difference? Your solution resulted in this error message: ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in query expression '%s'.") – C0ppert0p May 31 '17 at 18:53
  • Sorry missed the pyodbc tag. Here you have to use `?` instead of `%s` – e4c5 Jun 04 '17 at 00:07
  • Is this sorted out now? – e4c5 Jun 14 '17 at 23:44
  • Sorry, I discovered the error and posted the findings, right after found that that '%s' error, and then forgot to press the acceptance arrow. – C0ppert0p Jun 16 '17 at 19:52
1

In this case the correct Update statement is:

cursor.execute("""UPDATE ENCOMPASS_DIA SET CTIME=? WHERE SERNUM=?""", (SSTIME,ARCHIVE_SERNUM ))
C0ppert0p
  • 634
  • 2
  • 7
  • 23