def clear_db(): conn = get_connection() query = "delete from permission_requests;" cur = conn.cursor() cur.execute(query) query = "delete from doctors;" cur = conn.cursor() cur.execute(query) query = "delete from medical_records;" cur = conn.cursor() cur.execute(query) query = "delete from patients;" cur = conn.cursor() cur.execute(query) query = "delete from pharmacists;" cur = conn.cursor() cur.execute(query) query = "delete from prescriptions;" cur = conn.cursor() cur.execute(query) query = "delete from permissions;" cur = conn.cursor() cur.execute(query) conn.commit()
def close(): cursor = db_connection.get_cursor() cursor.close() conn = db_connection.get_connection() db_connection.release_connection(conn) db_connection.is_transaction = False
def begin(): logger.info('开启事物') db_connection.is_transaction = True db_connection.commit_point = False db_connection.connection = db_connection.get_connection() cursor = db_connection.get_cursor() cursor.execute('BEGIN') logger.info('事物已开启')
def insert_cart_id_with_coupon(cart_id, shop_id, coupon_code, automatic_added): conn = db_connection.get_connection() cursor = conn.cursor() insert_cart_id = ("INSERT INTO used_cart (cart_id, shop_id, coupon_code, automatic_added)" "VALUES (%s, %s, %s, %s)") insert_values = (cart_id, shop_id, coupon_code, automatic_added) cursor.execute(insert_cart_id, insert_values) db_connection.close_insert_connection(conn)
def insert_score_with_shop(score, shop_id): conn = db_connection.get_connection() cursor = conn.cursor() insert_score = ("INSERT INTO high_score (score, shop_id) " "VALUES (%s, %s)") insert_values = (score, shop_id) cursor.execute(insert_score, insert_values) db_connection.close_insert_connection(conn)
def select_shop_info(shop): conn = db_connection.get_connection() cursor = conn.cursor() get_shop = ("SELECT id, resource_owner_key, resource_owner_secret, client_key, client_secret " "FROM shop " "WHERE name = %(shop)s") cursor.execute(get_shop, {'shop': shop}) shop_data = cursor.fetchone() return shop_data
def setup_db(): conn = get_connection() cur = conn.cursor() query = "insert into prescriptions(type, meta) values('text','abc 50mg, xyx.10mg, etc..')" cur.execute(query) query = "insert into prescriptions(type, meta) values('image','http://somes3url')" cur.execute(query) query = "insert into pharmacists (id, org_name, licence, address) values('image','http://somes3url')" cur.execute(query) conn.commit()
def get_coupon_id_webshop(shop, score): conn = db_connection.get_connection() cursor = conn.cursor() shop_data = select_shop_info(shop) if shop_data is None: return None else: catalog_coupon_id = select_catalog_coupon_id_with_score(cursor, shop_data[0], score) db_connection.close_connection(conn) if catalog_coupon_id is not None: return shop_data + catalog_coupon_id else: return None
def select_coupon_with_cart_id(cart_id, shop_id): conn = db_connection.get_connection() cursor = conn.cursor() get_couponcode = ("SELECT coupon_code " "FROM used_cart " "WHERE cart_id = %s AND shop_id = %s") cart_shop_id = (cart_id, shop_id) cursor.execute(get_couponcode, cart_shop_id) coupon_code = cursor.fetchone() db_connection.close_connection(conn) if coupon_code is not None: return coupon_code else: return None
def __init__(self): self.conn = get_connection()
def insert_permission_into_db(): conn = get_connection() query = "insert into permissions(patient_id,requester_id,prescription_id,requester_type) values (1,1,1,'DR');" cur = conn.cursor() cur.execute(query) conn.commit()
def test_get_connection_pass(self): expected = None result = get_connection() self.assertNotEqual(expected, result)