23
Июл
2017

sqlite3 редактирование/замена вставленных в таблицу данных

Есть часть кода, которая в таблицу вставляет определенные данные, скажем, при значении self.baselinecount == 1. В случае, если self.baselinecount == 2 изменится, нужно будет отредактировать значения в ячейках. Собственно, вот код

def baseline_clicked(self):
        if self.baselinecount == 1:
            dialogbs = BaseLine(self.id_label.text())
            if dialogbs.exec_():

                target1type = dialogbs.target1_type.isChecked()
                target2type = dialogbs.target2_type.isChecked()
                target3type = dialogbs.target3_type.isChecked()
                target4type = dialogbs.target4_type.isChecked()
                target5type = dialogbs.target5_type.isChecked()

                target1name = dialogbs.target1_name.text()
                target2name = dialogbs.target2_name.text()
                target3name = dialogbs.target3_name.text()
                target4name = dialogbs.target4_name.text()
                target5name = dialogbs.target5_name.text()

                target1value = dialogbs.lineEdit.text()
                target2value = dialogbs.lineEdit_2.text()
                target3value = dialogbs.lineEdit_3.text()
                target4value = dialogbs.lineEdit_4.text()
                target5value = dialogbs.lineEdit_5.text()


                currentRowCount = self.tableWidget.rowCount()

                self.tableWidget.insertRow(currentRowCount)
                self.tableWidget.setItem(currentRowCount, 0, QTableWidgetItem('True' if target1type else 'False'))
                self.tableWidget.setItem(currentRowCount, 1, QTableWidgetItem('True' if target2type else 'False'))
                self.tableWidget.setItem(currentRowCount, 2, QTableWidgetItem('True' if target3type else 'False'))
                self.tableWidget.setItem(currentRowCount, 3, QTableWidgetItem('True' if target4type else 'False'))
                self.tableWidget.setItem(currentRowCount, 4, QTableWidgetItem('True' if target5type else 'False'))

                self.tableWidget.insertRow(currentRowCount)
                self.tableWidget.setItem(currentRowCount, 0, QTableWidgetItem(target1name))
                self.tableWidget.setItem(currentRowCount, 1, QTableWidgetItem(target2name))
                self.tableWidget.setItem(currentRowCount, 2, QTableWidgetItem(target3name))
                self.tableWidget.setItem(currentRowCount, 3, QTableWidgetItem(target4name))
                self.tableWidget.setItem(currentRowCount, 4, QTableWidgetItem(target5name))

                self.tableWidget.insertRow(currentRowCount)
                self.tableWidget.setItem(currentRowCount, 0, QTableWidgetItem(target1value))
                self.tableWidget.setItem(currentRowCount, 1, QTableWidgetItem(target2value))
                self.tableWidget.setItem(currentRowCount, 2, QTableWidgetItem(target3value))
                self.tableWidget.setItem(currentRowCount, 3, QTableWidgetItem(target4value))
                self.tableWidget.setItem(currentRowCount, 4, QTableWidgetItem(target5value))

                paramval = (None, target1value, target2value, target3value, target4value, target5value)
                self.dbCursor.execute("""INSERT INTO Main VALUES (?, ?, ?, ?, ?, ?)""", paramval)
                paramname = (None, target1name, target2name, target3name, target4name, target5name)
                self.dbCursor.execute("""INSERT INTO Main VALUES (?, ?, ?, ?, ?, ?)""", paramname)
                parameters = (None, str(target1type), str(target2type), str(target3type), str(target4type), str(target5type))
                self.dbCursor.execute("""INSERT INTO Main VALUES (?, ?, ?, ?, ?, ?)""", parameters)

                self.dbConn.commit()

Подскажите, как делается изменение введенных данных?

Источник: https://ru.stackoverflow.com/questions/696816/sqlite3-%D1%80%D0%B5%D0%B4%D0%B0%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%B7%D0%B0%D0%BC%D0%B5%D0%BD%D0%B0-%D0%B2%D1%81%D1%82%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%BD%D1%8B%D1%85-%D0%B2-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D1%83-%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85

Share

Тебе может это понравится...