Esempio n. 1
0
 def create_product_table(self):
     try:
         sql = CREATE_TABLE
         logging.info(sql)
         conn = get_connection()
         cursor = conn.cursor()
         cursor.execute(sql)
         conn.commit()
         return "Product Created Successfully..!"
     except BaseException as e:
         logging.error(e.args)
         return "Problem in Product create...!"
     finally:
         close_resources(conn, cursor)
Esempio n. 2
0
 def get_product(self, pid):
     if type(pid) == int and pid > 0:
         try:
             sql = FETCH_PRODUCT.format(pid)
             logging.info(sql)
             conn = get_connection()
             cursor = conn.cursor()
             cursor.execute(sql)
             record = cursor.fetchone()
             if record:
                 return Product(pid=record[0],
                                pnm=record[1],
                                pqty=record[2],
                                pven=record[4],
                                pprc=record[3])
         except BaseException as e:
             logging.error(e.args)
         finally:
             close_resources(conn, cursor)
Esempio n. 3
0
 def delete_product(self, pid):
     if type(pid) == int and pid > 0:
         dbprod = self.get_product(pid)
         if dbprod:
             try:
                 sql = DELETE_PRODUCT.format(pid)
                 logging.info(sql)
                 conn = get_connection()
                 cursor = conn.cursor()
                 cursor.execute(sql)
                 conn.commit()
                 return "Product deleted Successfully..!"
             except BaseException as e:
                 logging.error(e.args)
                 return "Problem in Product delete...!"
             finally:
                 close_resources(conn, cursor)
         else:
             return "Product with Given Id not exist..!"
     return "Invalid Product Type"
Esempio n. 4
0
 def update_product(self, pid, newvalues):
     if self.get_product(pid) and type(newvalues) == Product:
         try:
             sql = UPDATE_PRODUCT.format(newvalues.prodName,
                                         newvalues.prodQty,
                                         newvalues.prodPrice,
                                         newvalues.prodVendor,
                                         newvalues.prodId)
             logging.info(sql)
             conn = get_connection()
             cursor = conn.cursor()
             cursor.execute(sql)
             conn.commit()
             return "Product Updated Successfully..!"
         except BaseException as e:
             logging.error(e.args)
             return "Problem in Product Update...!"
         finally:
             close_resources(conn, cursor)
     return "Invalid Product Type or No product with Given Id Exist..!"
Esempio n. 5
0
 def get_all_products(self):
     try:
         sql = FETCH_ALL_PRODUCTS
         logging.info(sql)
         conn = get_connection()
         cursor = conn.cursor()
         cursor.execute(sql)
         records = cursor.fetchall()
         products = []
         for record in records:
             products.append(
                 Product(pid=record[0],
                         pnm=record[1],
                         pqty=record[2],
                         pven=record[4],
                         pprc=record[3]))
         return products
     except BaseException as e:
         logging.error(e.args)
     finally:
         close_resources(conn, cursor)
Esempio n. 6
0
 def add_product(self, prod):
     logging.info('Inside Add Product method')  # info
     if type(prod) == Product:
         dbprod = self.get_product(prod.prodId)
         if dbprod:
             logging.warning('Product WIth given Id already Present')
             return 'Duplicate PRoduct..!'
         try:
             sql = INSERT_PRODUCT.format(prod.prodId, prod.prodName,
                                         prod.prodQty, prod.prodPrice,
                                         prod.prodVendor)
             logging.info(sql)
             conn = get_connection()
             cursor = conn.cursor()
             cursor.execute(sql)
             conn.commit()
             return "Product Added Successfully..!"
         except BaseException as e:
             logging.error(e.args)
             return "Problem in Product Insert...!"
         finally:
             close_resources(conn, cursor)
     return "Invalid Product Type"