I have the following get_db() function that I use to get my SQLite database:
def get_db():
top = _app_ctx_stack.top
if not hasattr(top, 'sqlite_db'):
top.sqlite_db = sqlite3.connect(app.config['DATABASE'])
return top.sqlite_db
I believe i ma not using Python SQLite cursor here. If I do the following:
db = get_db()
db.execute('DELETE FROM table_name WHERE id=3')
db.commit()
How would I check if the ID passed in DELETE exists? I tried using rowcount in sqlite3.Cursor but that does not work with the way I am retrieving my database here.
How would I check for that? I need it to return 404 if the the ID passed does not exist.
Thanks
Why dont you query the ID first and throw 404 if does not exist. Something like: