Managing Blob of SQLite database table
« Basics of Python Tkinter « Full code with sample images
The main script is same for both the databases, only the connection string and the place holder for parameters in SQL is changed.
The changes required for using SQLite database in place of MySQL database is here.
Connection to SQLite Database
The connection object my_conn is created by using SQLite database, so in all script this line is to be changed.
For MySQL
my_conn = create_engine("mysql+mysqldb://userid:password@localhost/db_name")
For SQLite ( Change the path )
my_conn = create_engine("sqlite:///D:\\testing\\sqlite\\my_db.db")
While using placeholder for parameterized query for MySQL
id=my_conn.execute("INSERT INTO student_profile(id,student,profile_photo) \
VALUES (%s,%s,%s)",data)
For SQLite
id=my_conn.execute("INSERT INTO student_profile(id,student,profile_photo) \
VALUES (?,?,?)",data)
To create table and database in SQLite
from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError
try:
my_conn = create_engine("sqlite:///D:\\testing\\sqlite\\my_db.db")
print("Created database successfully")
my_conn.execute('''
CREATE TABLE IF NOT EXISTS student_profile(id integer,
student text,
profile_photo blob
)''')
#my_conn.commit()
print("Student Table created successfully")
except SQLAlchemyError as e:
error = str(e.__dict__['orig'])
print(error)
Displaying records from student table»
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com