Jonny1998
Jonny1998

Reputation: 107

Python script executing to SQL databse: COUNT field incorrect.. ERROR

I have some python script that executes to a SQL server. Error log says that something is happening in this, sqlInsrt() function. The error is:

pypyodbc.DatabaseError: ('07002', '[07002] [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error') 

Can anyone explain what is possibly going wrong here? I've had SQL errors before that are perhaps similar to this ("# of parameters expected, # of parameters given) for example

The function is below

def sqlInsrt(headers, values):
        #create string input of mylisth
        strheaders = ','.join(str(i) for i in headers)

        #create string input of %s corresponding to number of entries in mylisth
        placestr = ','.join(str(i) for i in ['?' for i in headers])

        #Setup and execute SQL query 
        replacestr = ', '.join(['{}=?'.format(h) for h in headers])
        insert = ("INSERT INTO capacitors ({strheaders}) VALUES ({placestr}) \
                  ON DUPLICATE KEY UPDATE {replacestr}").format(
                    strheaders=strheaders, placestr=placestr, replacestr=replacestr)
        cursor.execute(insert, values*2)
        cnx.commit()

Upvotes: 0

Views: 1066

Answers (1)

Aureliano Guedes
Aureliano Guedes

Reputation: 785

Does strheaders and placestr have same length? It looks like you're requiring wrong column.

Upvotes: 1

Related Questions