Reputation: 393
I have code to insert element into a Database:
def NewElement(new_user,new_pass):
querycurs.execute('''INSERT into Database (user,passw) values (?,?)''',(new_user,new_pass))
I want to execute the given statement only when the given value os new_user is not already present in the user column in the table. How can i do so?
Upvotes: 1
Views: 186
Reputation: 180270
Ensure that you have a UNIQUE
constraint on the user
column, either with a table constraint, with a unique index, or with a primary key.
Then replace INSERT with INSERT OR IGNORE.
Upvotes: 2