Try to fix race condition in frames and stations tables.
This commit is contained in:
		@@ -62,14 +62,15 @@ def main():
 | 
				
			|||||||
                attrib_names = ', '.join('"%s"' % w for w in a.keys())
 | 
					                attrib_names = ', '.join('"%s"' % w for w in a.keys())
 | 
				
			||||||
                attrib_values = ", ".join("?" * len(a.keys()))
 | 
					                attrib_values = ", ".join("?" * len(a.keys()))
 | 
				
			||||||
                sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
 | 
					                sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
 | 
				
			||||||
 | 
					                conn.commit()
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
                try:
 | 
					                try:
 | 
				
			||||||
                    # Insert data
 | 
					                    # Insert data
 | 
				
			||||||
                    conn.execute(sql, list(a.values()))
 | 
					                    conn.execute(sql, list(a.values()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    # TODO update stations table here
 | 
					                    # TODO update stations table here
 | 
				
			||||||
                    # Original intent was to include the id from the frames table,
 | 
					                    # Original intent was to include the id from the frames table,
 | 
				
			||||||
                    # but that would mean making another conn.commit() (I think).
 | 
					                    # but that would mean making another query.
 | 
				
			||||||
                    # It's not immediately needed, so I'm skipping it.
 | 
					                    # It's not immediately needed, so I'm skipping it.
 | 
				
			||||||
                    # Build query
 | 
					                    # Build query
 | 
				
			||||||
                    # "from" is wrappedin [] because it is a reserved word and using '' doesn't work.
 | 
					                    # "from" is wrappedin [] because it is a reserved word and using '' doesn't work.
 | 
				
			||||||
@@ -83,11 +84,10 @@ def main():
 | 
				
			|||||||
                        print(query3)
 | 
					                        print(query3)
 | 
				
			||||||
                        # Insert/update data
 | 
					                        # Insert/update data
 | 
				
			||||||
                        conn.execute(query3)
 | 
					                        conn.execute(query3)
 | 
				
			||||||
 | 
					                        conn.commit()
 | 
				
			||||||
                    except:
 | 
					                    except:
 | 
				
			||||||
                        print("Stations table couldn't be updated.")
 | 
					                        print("Stations table couldn't be updated.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    conn.commit()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    # TODO remove packets that are older ('created') than a limit set in config.ini
 | 
					                    # TODO remove packets that are older ('created') than a limit set in config.ini
 | 
				
			||||||
                    # "5 minutes" also works
 | 
					                    # "5 minutes" also works
 | 
				
			||||||
                    #conn.execute("DELETE FROM frames WHERE created < DATETIME('now', '"+config['Settings']['keep_time']+"')")
 | 
					                    #conn.execute("DELETE FROM frames WHERE created < DATETIME('now', '"+config['Settings']['keep_time']+"')")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user