I was trying to make a column in a sqlite3 database auto-increment, it works perfectly, but when I try to delete a column, the auto-increment becomes a little off, here are some images of db browser to explain you the same
Here, i created 3 columns, each with 7 rows, right now it works perfectly (fyi, the snippet_number row is auto-incrementing)
ok, so the problem starts here, when i delete the first row, the auto-increment for the first column is 2, which is wrong, as it should be 1
My question is that is their any way to fix this?
My code
This one creates the table, (it works flawlessly)
def set_up_db():
conn = sqlite3.connect('RobertSnippetStoreage.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS snippets (snippet_number INTEGER PRIMARY KEY, snippet TEXT, snippet_language TEXT,snippet_name TEXT, snippet_description TEXT, date_created REAL, times_used INTEGER)")
conn.commit()
return conn, cursor
This one inserts snippets
def insert_snippet(snippet, snippet_language ,snippet_name, snippet_description):
conn, cursor = set_up_db()
cursor.execute("INSERT INTO snippets (snippet_number, snippet, snippet_language, snippet_name, snippet_description, date_created, times_used) VALUES (?, ?, ?,?, ?, ?, ?)", (None,snippet, snippet_language, snippet_name, snippet_description, str(time.time()), 0))
conn.commit()
this one deletes snippets (this is where my problem is)
def delete_snippet(snippet_number):
conn, cursor = set_up_db()
cursor.execute("DELETE FROM snippets WHERE snippet_number=?", (snippet_number, ))
conn.commit()