not too experienced with SQL, wondering if I can make this better... I am trying to check if a row exists and then add one to the frequency column if it does, if it does not exist it should return false...
The table is indexed by the column in the first select statement
I know about the risks of using formatting with public facing code, but this is for processing on a local machine only
def check_word(self, word_name):
self.c.execute('SELECT * FROM {tn} WHERE {cn} = """{wn}"""'.format(tn=self.table1, cn=self.column1, wn=word_name))
exist = self.c.fetchall()
if exist:
new_freq = exist[0][2] + 1
self.c.execute(
'UPDATE {tn} SET {c2n}={en} WHERE {c1n}="""{word}"""'.format(tn=self.table1, c2n=self.column2,
en=new_freq, c1n=self.column1,
word=word_name))
return True
return False
SELECT col_a, col_b FROM table WHERE (Some conditions)
rather thanSELECT * FROM table WHERE (Some conditions)
\$\endgroup\$