def add_category(data): cursor = conn.cursor() cursor.callproc('add_category', [ len(data["parent"].split(".")) + 1, data["name"], data["parent"], ]) conn.commit()
def remove_product(id): cursor = conn.cursor() cursor.execute( """delete from list_brand_product where prod_id = %(prod_id)s""", {"prod_id": id}) cursor.execute("""delete from product where prod_id = %(prod_id)s""", {"prod_id": id}) conn.commit()
def update_category(data): cursor = conn.cursor() cursor.execute( """update category set cat_name = %(cat_name)s where cat_num = %(cat_num)s""", { "cat_name": data["name"], "cat_num": data["id"] }) conn.commit()
def update_shop_info(data): cursor = conn.cursor() cursor.execute( """update shop set name = %(name)s, phone = %(phone)s, address = %(address)s""", { "name": data["name"], "phone": data["phone"], "address": data["address"] }) conn.commit()
def remove_category(id): cursor = conn.cursor() cursor.execute("""delete from category where cat_num = %(cat_num)s;""", {"cat_num": id}) cursor.execute( """delete from list_brand_product where prod_id IN (select prod_id from product where cat_num = %(cat_num)s);""", {"cat_num": id}) cursor.execute("""delete from product where cat_num = %(cat_num)s;""", {"cat_num": id}) conn.commit()
def update_brand(data): cursor = conn.cursor() cursor.execute( """update brand set br_name = %(br_name)s, br_description = %(desc)s, img_url = %(img)s where br_id = %(br_id)s""", { "br_id": data["id"], "br_name": data["name"], "desc": data["description"], "img": data["img_url"] }) conn.commit()
def add_brand(data): cursor = conn.cursor() cursor.execute("""select max(br_id) from brand""") br_id = cursor.fetchall()[0][0] + 1 cursor.execute( """insert into brand (br_id, br_name, br_description, img_url) values (%(br_id)s, %(br_name)s, %(desc)s, %(img)s)""", { "br_id": br_id, "br_name": data["name"], "desc": data["description"], "img": data["img_url"] }) conn.commit()
def update_product(data): cursor = conn.cursor() cursor.execute( """update product set prod_name = %(name)s, price = %(price)s, installment_plan = %(plan)s, warranty_period = %(period)s, img_url = %(image)s, description = %(desc)s, cat_num = %(num)s where prod_id = %(id)s""", { "id": data["id"], "name": data["name"], "price": data["price"], "plan": data["installment_plan"], "period": data["warranty_period"], "num": data["category"], "image": data["img_url"], "desc": data["description"] }) cursor.execute("""delete from list_brand_product where prod_id = %(id)s""", {"id": data["id"]}) cursor.execute( """insert into list_brand_product(br_id, prod_id) values(%(br_id)s, %(prod_id)s)""", { "br_id": data["brand"], "prod_id": data["id"] }) conn.commit()
def add_product(data): cursor = conn.cursor() cursor.execute("""select max(prod_id) from product""") prod_id = cursor.fetchall()[0][0] + 1 cursor.execute( """insert into product (prod_id, prod_name, price, installment_plan, warranty_period, cat_num, img_url, description) values (%(id)s, %(name)s, %(price)s, %(plan)s, %(period)s, %(num)s, %(image)s, %(desc)s)""", { "id": prod_id, "name": data["name"], "price": data["price"], "plan": data["installment_plan"], "period": data["warranty_period"], "num": data["category"], "image": data["img_url"], "desc": data["description"], }) cursor.execute( """insert into list_brand_product (br_id, prod_id) values(%(br_id)s, %(prod_id)s);""", { "br_id": data["brand"], "prod_id": prod_id }) conn.commit()
def remove_brand(id): cursor = conn.cursor() cursor.execute("""delete from brand where br_id = %(br_id)s""", {"br_id": id}) conn.commit()