Skip to content

Instantly share code, notes, and snippets.

@hottabxp
Created February 19, 2020 16:53
Show Gist options
  • Save hottabxp/bc79d8cfe62f2fd34ccaa783d3b7a92b to your computer and use it in GitHub Desktop.
Save hottabxp/bc79d8cfe62f2fd34ccaa783d3b7a92b to your computer and use it in GitHub Desktop.
Write image to sqlite3
import sqlite3
import base64
file_db = 'mydb.db'
def create_db(filename):
conn = sqlite3.connect(filename)
cursor = conn.cursor()
cursor.execute("CREATE TABLE MyTable(id INTEGER,name TEXT)")
def add_data(filename,id,name,bin):
conn = sqlite3.connect(filename)
cursor = conn.cursor()
cursor.execute(f"INSERT INTO MyTable VALUES(?,?,?)",[id,name,bin])
conn.commit()
def get_data(filename):
conn = sqlite3.connect(filename)
cursor = conn.cursor()
cursor.execute("SELECT * FROM MyTable WHERE id=3")
return cursor.fetchall()
# create_db(file_db)
def read_image():
file = open('1.png','rb')
return file.read()
img = read_image()
for x in range(0,1000):
add_data(file_db,'111',' ',sqlite3.Binary(img))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment