Created
August 22, 2020 07:48
-
-
Save BexTuychiev/20cae983c66e647b0f4bef8fded8e4c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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