I'd like to make an if statement which compares a value inserted in QLineEdit, with a value (primary key) from a table, and if it already exists, it shows message "Identification number you've entered is already in use".
This is the most important part of the code:
class kirurg_GUI(QtGui.QWidget, Ui_kirurg_Widget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
self.kirurg_Add_button.clicked.connect(self.insert_kirurg)
def insert_kirurg(self):
query = QSqlQuery()
query.exec("INSERT INTO kirurg (oib_kir, prezime, ime, adresa, broj_telefona)"
"VALUES ('%s', '%s', '%s', '%s', '%s')" % (''.join(self.kirurg_oib_kir_lineEdit.text()),
''.join(self.kirurg_prezime_lineEdit.text()),
''.join(self.kirurg_ime_lineEdit.text()),
''.join(self.kirurg_adresa_lineEdit.text()),
''.join(self.kirurg_broj_telefona_lineEdit.text())))
So basically, when kirurg_Add_button
is clicked it should add new row in database (consisting of these five values), but only if the first value kirurg_oib_kir
doesn't already exist as a primary key in my database.