from PIL import Image
import io
Our binary data is available in row[2]
image = Image.open(io.BytesIO(row[2]))
import matplotlib.pyplot as plt
plt.imshow(image)
plt.show()
Full code to manage SQLite Blob column data in google platform is here
# download student_blob.db SQLite Database from plus2net.com
!wget https://www.plus2net.com/python/download/student_blob.db
import sqlite3 # Connection library
my_conn = sqlite3.connect('student_blob.db') # connect to db
from PIL import Image
import io
import matplotlib.pyplot as plt
query="pragma table_info([student_profile])"
my_data=list(my_conn.execute(query)) # structure
print(my_data) # Listing structure of table
r_set=my_conn.execute('SELECT * from student_profile ');
for row in r_set:
image = Image.open(io.BytesIO(row[2]))
plt.figure(figsize=(1,1))
plt.axis(False)
plt.imshow(image)
print(row[0],row[1],'')
plt.show()
from sqlalchemy import create_engine,text
from sqlalchemy.exc import SQLAlchemyError
my_conn=create_engine("sqlite:///student_blob.db"+'?check_same_thread=False')
my_conn=my_conn.connect()
from PIL import Image
import io
my_data=(1) # ID of the row to display
q="SELECT * FROM student_profile WHERE id=1" # query with place holders
try:
my_cursor=my_conn.execute(text(q))
r_set=my_cursor.fetchone()
except SQLAlchemyError as e:
#error=str(e.__dict__['orig'])
print(e)
else:
student=str(r_set[0])+','+r_set[1]
#print(student)
image = Image.open(io.BytesIO(r_set[2]))
import matplotlib.pyplot as plt
plt.imshow(image)
plt.show()
Managing SQLite Database in Google Colab platform . Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.