Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't delete information from table made with information pulled from sqlite3
Forum Updated to NodeBB v4.3 + New Features

Can't delete information from table made with information pulled from sqlite3

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 233 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SpeeDEV
    wrote on last edited by
    #1

    Hello,

    I enter the information first through the interface, then register it. There is no problem here. But I cannot delete the data inserted in the table.

    Interface code:
    from PyQt5 import QtWidgets
    from PyQt5.QtWidgets import QTableWidgetItem, QHeaderView
    
    from Ui_tamir import Ui_Dialog
    
    import sys
    import os
    import sqlite3 as sql
    
    os.system("python Baglan.py")
    os.system("python TabloOlustur.py")
    
    global urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat
    
    class Window(QtWidgets.QMainWindow):
        def __init__(self):
            super(Window, self).__init__()
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
    
            self.formYukle()
            self.ui.kaydetButon.clicked.connect(self.butonKaydetTiklandi)
            self.ui.silButon.clicked.connect(self.sil)
    
        def formYukle(self):
            self.ui.eklenenlerTablo.clear()
            self.ui.eklenenlerTablo.setColumnCount(7)
            self.ui.eklenenlerTablo.setHorizontalHeaderLabels(("Urun NO", "Ad-soyad", "Telefon NO", "Esya", "Parca", "Yapilacaklar", "Fiyat"))
            self.ui.eklenenlerTablo.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
    
            db = sql.connect("bilgiler.db")
            cur = db.cursor()
            sorgu = "Select * from TBilgiler"
            cur.execute(sorgu)
    
            satirlar = cur.fetchall()
    
            self.ui.eklenenlerTablo.setRowCount(len(satirlar))
    
            for satirIndeks, satirVeri in enumerate(satirlar):
                for sutunIndeks, sutunVeri in enumerate(satirVeri):
                    self.ui.eklenenlerTablo.setItem(satirIndeks, sutunIndeks, QTableWidgetItem(str(sutunVeri)))
    
        def butonKaydetTiklandi(self):
            urunno = self.ui.urunNoGiris.toPlainText()
            alacakkisiadsoyad = self.ui.urunNoGiris_2.toPlainText()
            telno = self.ui.telNoGiris.toPlainText()
            esya = self.ui.esyaGiris.toPlainText()
            parca = self.ui.parcaGiris.toPlainText()
            yapilacaklar = self.ui.yapilacaklarGiris.toPlainText()
            fiyat = self.ui.fiyatGiris.toPlainText()
    
            try:
                self.baglanti = sql.connect("bilgiler.db")
                self.c = self.baglanti.cursor()
                self.c.execute("INSERT INTO TBilgiler Values(?, ?, ?, ?, ?, ?, ?)", (urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat))
                self.baglanti.commit()
                self.c.close()
                print("Başarılı", "bilgiler başarıyla gönderildi")
    
            except:
                print("Hata", "Hata !!!!!!")
    
        def sil(self):
            uruno = self.ui.urunNoGiris.toPlainText()
    
            
            self.baglanti = sql.connect("bilgiler.db")
            self.c = self.baglanti.cursor()
            self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,))
            self.baglanti.commit()
            self.c.close()
            self.baglanti.close()
            print("Urun silindi")
    
            self.sil()
            self.formYukle()
    
    def app():
        app = QtWidgets.QApplication(sys.argv)
        win = Window()
        win.show()
        sys.exit(app.exec_())
    
    app()
    

    I think the problem is in this code:
    ```
    def sil(self):
    uruno = self.ui.urunNoGiris.toPlainText()

        self.baglanti = sql.connect("bilgiler.db")
        self.c = self.baglanti.cursor()
        self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,))
        self.baglanti.commit()
        self.c.close()
        self.baglanti.close()
        print("Urun silindi")
    
        self.sil()
        self.formYukle()
    
    JonBJ 1 Reply Last reply
    0
    • S SpeeDEV

      Hello,

      I enter the information first through the interface, then register it. There is no problem here. But I cannot delete the data inserted in the table.

      Interface code:
      from PyQt5 import QtWidgets
      from PyQt5.QtWidgets import QTableWidgetItem, QHeaderView
      
      from Ui_tamir import Ui_Dialog
      
      import sys
      import os
      import sqlite3 as sql
      
      os.system("python Baglan.py")
      os.system("python TabloOlustur.py")
      
      global urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat
      
      class Window(QtWidgets.QMainWindow):
          def __init__(self):
              super(Window, self).__init__()
              self.ui = Ui_Dialog()
              self.ui.setupUi(self)
      
              self.formYukle()
              self.ui.kaydetButon.clicked.connect(self.butonKaydetTiklandi)
              self.ui.silButon.clicked.connect(self.sil)
      
          def formYukle(self):
              self.ui.eklenenlerTablo.clear()
              self.ui.eklenenlerTablo.setColumnCount(7)
              self.ui.eklenenlerTablo.setHorizontalHeaderLabels(("Urun NO", "Ad-soyad", "Telefon NO", "Esya", "Parca", "Yapilacaklar", "Fiyat"))
              self.ui.eklenenlerTablo.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
      
              db = sql.connect("bilgiler.db")
              cur = db.cursor()
              sorgu = "Select * from TBilgiler"
              cur.execute(sorgu)
      
              satirlar = cur.fetchall()
      
              self.ui.eklenenlerTablo.setRowCount(len(satirlar))
      
              for satirIndeks, satirVeri in enumerate(satirlar):
                  for sutunIndeks, sutunVeri in enumerate(satirVeri):
                      self.ui.eklenenlerTablo.setItem(satirIndeks, sutunIndeks, QTableWidgetItem(str(sutunVeri)))
      
          def butonKaydetTiklandi(self):
              urunno = self.ui.urunNoGiris.toPlainText()
              alacakkisiadsoyad = self.ui.urunNoGiris_2.toPlainText()
              telno = self.ui.telNoGiris.toPlainText()
              esya = self.ui.esyaGiris.toPlainText()
              parca = self.ui.parcaGiris.toPlainText()
              yapilacaklar = self.ui.yapilacaklarGiris.toPlainText()
              fiyat = self.ui.fiyatGiris.toPlainText()
      
              try:
                  self.baglanti = sql.connect("bilgiler.db")
                  self.c = self.baglanti.cursor()
                  self.c.execute("INSERT INTO TBilgiler Values(?, ?, ?, ?, ?, ?, ?)", (urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat))
                  self.baglanti.commit()
                  self.c.close()
                  print("Başarılı", "bilgiler başarıyla gönderildi")
      
              except:
                  print("Hata", "Hata !!!!!!")
      
          def sil(self):
              uruno = self.ui.urunNoGiris.toPlainText()
      
              
              self.baglanti = sql.connect("bilgiler.db")
              self.c = self.baglanti.cursor()
              self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,))
              self.baglanti.commit()
              self.c.close()
              self.baglanti.close()
              print("Urun silindi")
      
              self.sil()
              self.formYukle()
      
      def app():
          app = QtWidgets.QApplication(sys.argv)
          win = Window()
          win.show()
          sys.exit(app.exec_())
      
      app()
      

      I think the problem is in this code:
      ```
      def sil(self):
      uruno = self.ui.urunNoGiris.toPlainText()

          self.baglanti = sql.connect("bilgiler.db")
          self.c = self.baglanti.cursor()
          self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,))
          self.baglanti.commit()
          self.c.close()
          self.baglanti.close()
          print("Urun silindi")
      
          self.sil()
          self.formYukle()
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @SpeeDEV
      You use the Python sqlite3 library for all your data access. Wouldn't your question best be directed there, I don't see it's to do with Qt?

      Would it be an idea to print out what is actually in uruno = self.ui.urunNoGiris.toPlainText()?

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Did you check that your database calls are successful ?
        Did you also consider using Qt's SQL module ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved