I want the table to have a maximum of three rows so once the table has 3, it should delete the oldest one (rowid 1) and then add on the new one. In the case that the table doesn't exist yet or hasn't reached 3 rows, it will just create the record normally. Everything works except for deleting the first row. Although there is no error feedback either and when the command is executed in the DB browser 'execute SQL' it works perfectly, it just doesn't work when run from my IDE. The new record is made but on top of the three already there instead of being added as the third after the first is deleted.
cursor.execute("SELECT count(*) from TableOne")
searchResults = cursor.fetchone()
NoOfRows=searchResults[0]
if NoOfRows ==3:
cursor.execute("DELETE FROM TableOne WHERE rowid=1")
connection.close()
CreateNew()
else:
CreateNew()
Note that the connection to the database is established before this code and 'CreateNew' is a function that creates the new record in the table. Additionally, I have tried:
Num=1
cursor.execute("DELETE FROM TableOne WHERE rowid=?",[Num])
Only to have the same result.