So, I have a very simple application that receives a request via a rest API, writes a record to a database using SQLite and then sends a rest API call to another server on the internet. When I send the rest API call to the server on the internet, that server does some network processing and then sends a response back to me which I then update the record.
The problem I'm having is that the process of sending the API call to the server and getting the response back is completed before the initial write occurs to SQLite. Therefore, when I try to update the database it doesn't exist. On the insert of the data, I do a commit, but does anyone know why the write isn't as instantaneous as I would assume?
My code is below to do the insert: Yes the insert works
def insert_into_database(dbname,table,**kwargs):
conn = sqlite3.connect(dbname)
#generate a unique ID
id=get_a_uuid()
#generate the current date for timestamps
d=datetime.datetime.now()
fieldnames,values = create_command_line(kwargs)
insert="INSERT INTO "+table+" (ID,DATE,"+fieldnames+") VALUES ('"+id+"','"+str(d)+"',"+values+")"
print (insert)
try:
conn.execute(insert)
conn.commit()
except (sqlite3.Error) as e:
print(e)
return(False,str(e))
conn.close()
return(True,id)