May-22-2023, 07:42 AM
(This post was last modified: May-22-2023, 07:42 AM by gratiszzzz.)
(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!