Skip to content

Commit

Permalink
display blob image - 0
Browse files Browse the repository at this point in the history
  • Loading branch information
vanguardmaster01 committed Sep 7, 2023
1 parent 1908bd7 commit 24edbc1
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 195 deletions.
Binary file modified DbFuncs/__pycache__/db.cpython-311.pyc
Binary file not shown.
36 changes: 30 additions & 6 deletions DbFuncs/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@


# convert image to blob data
def convertToBlobData(filename):
def convert_to_blod_data(filename):
with open(filename, 'rb') as file:
blobData = file.read()
return blobData


# insert into product table
def insertProduct(product):
def insert_product(product):
try:
conn = sqlite3.connect(constants.dbPath)
cursor = conn.cursor()

insert_query = """insert into products (name, image, count, price, modifiedAt)
values (?, ?, ?, ?, ?)"""

imageBlob = convertToBlobData(product.image)
imageBlob = convert_to_blod_data(product.image)
data = (product.name, imageBlob, product.count, product.price, datetime.datetime.now())

cursor.execute(insert_query, data)
Expand All @@ -49,7 +49,7 @@ def insertProduct(product):
return False

# update product item
def updateProduct(id, count):
def update_product(id, count):
try:
conn = sqlite3.connect(constants.dbPath)
cursor = conn.cursor()
Expand All @@ -69,12 +69,12 @@ def updateProduct(id, count):
print('connection is closed')

# get all products
def getProducts():
def get_products():
try:
conn = sqlite3.connect(constants.dbPath)
cursor = conn.cursor()

select_query = '''select id, name, count from products'''
select_query = '''select id, name, image, count, price from products'''
cursor.execute(select_query)
records = cursor.fetchall()

Expand All @@ -90,3 +90,27 @@ def getProducts():
print('connection is closed')

return records

# get product
def get_product(id):
try:
conn = sqlite3.connect(constants.dbPath)
cursor = conn.cursor()

print(f'id: {id}')
select_query = '''select id, name, count, price from products where id = ?'''
cursor.execute(select_query, (id,))
record = cursor.fetchone()

conn.commit()
cursor.close()

except sqlite3.Error as error:
print('fail', error)
record = None
finally:
if conn:
conn.close()
print('connection is closed')

return record
2 changes: 1 addition & 1 deletion DbFuncs/db_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


# create product table
def createDb():
def create_table_if_not_exists():
try:
conn = sqlite3.connect(constants.dbPath)
cursor = conn.cursor()
Expand Down
14 changes: 8 additions & 6 deletions DbFuncs/db_get_list_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
conn = sqlite3.connect(constants.dbPath)
cursor = conn.cursor()

# Get All Users
get_all_users_query = '''select id, name, price from products'''
cursor.execute(get_all_users_query)
records = cursor.fetchall()

print(records)

cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")

Expand All @@ -27,6 +21,14 @@
for table in tables:
print(table[0])

# Get All Products
get_all_data_query = '''select id, name, price from products'''
cursor.execute(get_all_data_query)
records = cursor.fetchall()

print(records)



conn.commit()
cursor.close()
Expand Down
Binary file modified DbFuncs/sql.db
Binary file not shown.
16 changes: 1 addition & 15 deletions kv/list.kv
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,9 @@ WindowManager:
size: self.texture_size

GridLayout:
id: image_layout
cols: 2
rows: 2
spacing: 30
padding: 10
Image:
source: './img/1-1.png'
size: self.texture_size
on_touch_down: root.select_item()
Image:
source: './img/1-2.png'
size: self.texture_size
Image:
source: './img/2-1.png'
size: self.texture_size
Image:
source: './img/2-2.png'
size: self.texture_size

BoxLayout:
padding: 10, 10, 10, 10
Expand Down
153 changes: 0 additions & 153 deletions list.kv

This file was deleted.

Loading

0 comments on commit 24edbc1

Please sign in to comment.