Use sqlite3_close_v2, it automatically closes the db after the last statement finishes