Python Forum
Error 1064 (42000) when executing UPDATE SQL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error 1064 (42000) when executing UPDATE SQL
#4
(May-22-2023, 07:18 AM)ibreeden Wrote: Which database are you using? Please show us your program and the complete error message.
You are calling execute_query(). Where is it defined?


Hi ibreeden!

I am using MariaDB.

def create_connection(host_name, user_name, user_password, db_name):
    connection = None
    try:
        connection = mysql.connector.connect(
            host=host_name,
            user=user_name,
            passwd=user_password,
            database=db_name
        )
        
    except Error as e:
        falla_conexion = 1
        print("lo que esta fallando es la conexion")
       

    return connection

def execute_query(connection, query):
    cursor = connection.cursor()
    try:
        cursor.execute(query)
        print("La consulta se ejecutó correctamente.")

        return 1
    except Error as e:
        print("Hubo un error al ejecutar la consulta: " + str(e))
        return 0
    finally:
        cursor.close()

def execute_read_query(connection, query):
    cursor = connection.cursor()
    result = None
    try:
        cursor.execute(query)
        result = cursor.fetchall()
        return len(result)
    except Error as e:
        print("The error consulta numerica occurred")



sql_actualizar_ficha_es = "UPDATE ps_product_lang SET description = '--', name = '" + titulo + "' WHERE id_product = " + id_producto + " AND id_lang = 1;"
    sql_actualizar_ficha_pt = "UPDATE ps_product_lang SET description = '--', name = '" + titulo_pt + "' WHERE id_product = " + id_producto + " AND id_lang = 2;"
    sql_registrar_id_producto = "INSERT INTO fichas_actualizadas (id_product) VALUES ('" + id_producto + "');"   

    connection = create_connection("?????", "¿¿¿¿¿", "???????", "???????") 
    
    consulta1 = execute_query(connection, sql_actualizar_ficha_es) 
    consulta2 = execute_query(connection, sql_actualizar_ficha_pt) 

    print("-----------------------------------------")
    print(sql_actualizar_ficha_es)
    if consulta1 == 1 and consulta2 == 1 :
        consulta3 = execute_query(connection, sql_registrar_id_producto) 
The error output that appears when running the script is:

Hubo un error al ejecutar la consulta: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
Hubo un error al ejecutar la consulta: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
-----------------------------------------
UPDATE ps_product_lang SET description = '--', name = 'Teclado Value con cable' WHERE id_product = 278333 AND id_lang = 1;

Something that really catches my attention is that if I take the same sql query that I'm trying to execute in the script with the error and paste it into phpmyadmin, it runs without any problem.

I am completely lost.....

Thank you so much!
Reply


Messages In This Thread
RE: Error 1064 (42000) when executing UPDATE SQL - by gratiszzzz - May-22-2023, 07:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error while executing the Python code in Linux DivAsh 8 1,889 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  error 1102 (42000) incorrect database name 's' Anldra12 4 1,783 Jun-08-2022, 09:00 AM
Last Post: Anldra12
  SSL error while trying to update conda ilango 0 2,241 Nov-04-2021, 08:38 AM
Last Post: ilango
  Eliminating error in Python update-alternatives Led_Zeppelin 2 3,080 Apr-14-2021, 12:49 PM
Last Post: Led_Zeppelin
  Facing error while executing below Python code ramu4651 1 5,865 Jan-26-2021, 06:40 PM
Last Post: ibreeden
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,780 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Error when executing pytesseract to get the text from image bvdinesh 3 18,165 Oct-19-2019, 05:01 PM
Last Post: cwco00
  pymysql.err.ProgrammingError : 1064 You have an error in your SQL syntax pradeepkumarbe 1 12,777 Jul-01-2019, 08:05 AM
Last Post: pradeepkumarbe
  Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2 Newtopython123 10 31,533 Apr-25-2019, 07:30 AM
Last Post: banu0395
  Cannot update or install anything with pip, SSL error nickystixx45 6 180,922 Mar-26-2019, 03:42 AM
Last Post: nickystixx45

Forum Jump:

User Panel Messages

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