Skip to content

Instantly share code, notes, and snippets.

@BexTuychiev
Created August 22, 2020 07:48
Show Gist options
  • Save BexTuychiev/20cae983c66e647b0f4bef8fded8e4c6 to your computer and use it in GitHub Desktop.
Save BexTuychiev/20cae983c66e647b0f4bef8fded8e4c6 to your computer and use it in GitHub Desktop.
def retrieve_file(file_name, db_name, table_name):
try:
# Establish a connection
connection = sqlite_connect(db_name)
print(f"Connected to the database `{db_name}`")
# Create a cursor object
cursor = connection.cursor()
sql_retrieve_file_query = f"""SELECT * FROM {table_name} WHERE name = ?"""
cursor.execute(sql_retrieve_file_query, (file_name,))
# Retrieve results in a tuple
record = cursor.fetchone()
# Save to a file
write_to_file(record[1], record[0])
except sqlite3.Error as error:
print("Failed to insert blob into the table", error)
finally:
if connection:
connection.close()
print("Connection closed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment