Python Forum
MySQL executemany - Failed executing the operation; Could not process parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySQL executemany - Failed executing the operation; Could not process parameters
#1
I've written a bit of python code that essentially will take data from one database (SQL Server 2008) and insert it into another (MySQL). I am fairly new to python so am struggling to find the errors in my code. The problem is with the executemany line as when I comment this out the error goes away.

My code is:
import mysql.connector
import pyodbc

def insert_VPS(SageResult):
    query = """
INSERT INTO SOPOrderReturn(SOPOrderReturnID,DocumentTypeID,DocumentNo,DocumentDate,CustomerID,CustomerTypeID,CurrencyID,SubtotalGoodsValue,TotalNetValue,TotalTaxValue,TotalGrossValue,SourceTypeID,SourceDocumentNo)
VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
    try:
        mydbVPS = mysql.connector.connect(
          host="serveraddress",
          user="username",
          passwd="password;",
          database="databse"
        )

        VPScursor = mydbVPS.cursor()
        print(SageResult)
        VPScursor.executemany(query, SageResult)


        mydbVPS.commit()
    except Exception as e:
        print('InsertError:', e)

    finally:
        VPScursor.close()
        mydbVPS.close()

def main():
    selectQuery = """
SELECT TOP 1 [SOPOrderReturnID]
      ,[DocumentTypeID]
      ,[DocumentNo]
      ,[DocumentDate]
      ,[CustomerID]
      ,[CustomerTypeID]
      ,[CurrencyID]
      ,[SubtotalGoodsValue]
      ,[TotalNetValue]
      ,[TotalTaxValue]
      ,[TotalGrossValue]
      ,[SourceTypeID]
      ,[SourceDocumentNo]
  FROM [Live].[dbo].[SOPOrderReturn]
"""


    try:
        mydbSage = pyodbc.connect('Driver={SQL Server};'
                      'Server=CRMTEST;'
                      'Database=Live;'
                      'UID=sa;'
                      'PWD=password;')

        Sagecursor = mydbSage.cursor()

        Sagecursor.execute(selectQuery)
        SageResult = tuple(Sagecursor.fetchall())


        mydbSage.commit()
    except Exception as e:
        print('MainError:', e)

    finally:
        Sagecursor.close()
        mydbSage.close()

    insert_VPS(SageResult)


if __name__ == '__main__':
    main()
Output:
Output:
D:\xampp\htdocs\stripe\group\beta>sql-sync.py ((10447177, 0, '0000091897', datetime.datetime(2010, 8, 18, 0, 0), 186150, 1, 1, Decimal('18896.95'), Decimal('18896.95'), Decimal('3779.39'), Decimal('22676.34 '), 0, ''),) InsertError: Failed executing the operation; Could not process parameters
All of the connections work as I've tested those separately. Can anyone see the issues? Any help would be greatly appreciated.
Reply
#2
There is no table named SOPOrderReturn that I can see in the code you posted, so you are trying to insert into something that doesn't exist. For more help post the complete traceback.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 664 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Command error - cursor.executemany(comandoSQL,valoresInserir) TecInfo 2 1,347 Nov-18-2022, 01:57 PM
Last Post: TecInfo
  Failed to execute child process (No such file or directory) uriel 1 1,651 Sep-15-2022, 03:48 PM
Last Post: Gribouillis
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,993 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,590 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Mysql. Not all parameters were used in the SQL statement cybertooth 5 18,704 Oct-14-2021, 05:01 AM
Last Post: cybertooth
  MERGE SQL in oracle executemany kaladin 0 3,092 Oct-12-2020, 11:48 AM
Last Post: kaladin
  Failed to insert record into MySQL table.Python type tuple cannot be converted farah97 3 21,557 Dec-26-2019, 02:01 PM
Last Post: buran
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,656 Sep-03-2019, 09:49 PM
Last Post: woooee
  Using executemany to import the data Sandy7771989 1 2,679 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020