Updates SQL statement to fill images table to ignore errors when a record exists.
Changes function that handles database connection to a context manager to guarantee connections being closed, both on a successful execution of the scripts, as well as on failure. This prevents the accumulation of dangling connections on the database.
Some refactoring to attempt to make the distinction between inserts to the images and detections tables clearer.
Changes database connection to autocommit since we are committing immediately after generating a SQL statement anyway. Should also prevent long running connections/table locks when the program fails between uncommitted SQL statements.