Erreur python

merci de m aider a resoudre le probleme:

pymysql.err.ProgrammingError: (1064, "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 'LIKE'%dalaoui%'' at line 1")

mon code est:

def search(self):

        con=pymysql.connect(host='localhost',user='root',password='',database='client')

        cur=con.cursor()

        cur.execute("select * from client WHERE" +

        str(self.search2_var.get())+"LIKE'%"+str(self.search1_var.get())+"%'")

        rows=cur.fetchall()

        if len(rows)!=0:

           self.Client_table.delete(*self.Client_table.get_children())

            for row in rows:

                self.Client_table.insert("",END,value=row)

                   con.commit()

                  con.close()      

3 réponses

  1. Bonjour, et si tu affichais ce que donne ton sql ? Tu verrais déjà qu'il manque des espaces, et plutôt qu'utiliser une concaténation, sers-toi de format de python.

    sql = f"SELECT * from client WHERE {self.search2_var.get()} LIKE %{self.search1_var.get()}%"
    0
    1. Je suis débutant, je veux juste le bon syntaxe afin de ne pas avoir l erreur et qui peut remplacer le mien

      pymysql.err.ProgrammingError: (1064, "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 'LIKE'%dalaoui%'' at line 1")

      def search(self):
      
              con=pymysql.connect(host='localhost',user='root',password='',database='client')
      
              cur=con.cursor()
      
              cur.execute("select * from client WHERE" +
      
              str(self.search2_var.get())+"LIKE'%"+str(self.search1_var.get())+"%'")
      
              rows=cur.fetchall()
      
              if len(rows)!=0:
      
                 self.Client_table.delete(*self.Client_table.get_children())
      
                  for row in rows:
      
                      self.Client_table.insert("",END,value=row)
      
                         con.commit()
      
                        con.close()      
      0
      1. Contributeur Ambassadeur

        bonjour,

        quelle est la différence entre ton commentaire et ta question initiale?

        0
    2. Yg_be, aide moi si tu peux stp

      0