Answer the question
In order to leave comments, you need to log in
How to remove connection is already closed error?
Here is the actual function where the error occurs:
def Onclicke(self):
flag = 0
login = (self.lineEdit.text(), )
passw = (self.lineEdit_2.text(),)
strana = str(self.comboBox.currentText())
print(strana)
with connection:
curs = connection.cursor()
curs.execute("SELECT username, код_покупателя FROM клиент "
"ORDER BY код_покупателя")
test = curs.fetchall()
last = test[len(test)-1][1]
last += 1
curs.execute("SELECT username FROM клиент")
logs = curs.fetchall() # выполнение запроса
for row in logs:
if row == login:
flag = 1
if flag == 1:
self.label_3.setStyleSheet("color: rgb(255, 0, 0);")
self.label_3.setText("congratulations!")
else:
self.label_3.setStyleSheet("color: rgb(65, 211, 89);")
self.label_3.setText("Логин уже существует")
curs.execute("INSERT into клиент values (%s, %s, %s, %s)", (login[0], last, strana, passw[0]))
connection.commit()
curs.close()
connection.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question