def user(): try: conn mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute("SELECT * FROM details") rows = cur.fetchall() resp = jsonify(rows) resp.status_code = 200 return resp except Exception as e: print(e) finally: cur.close() conn.close()
def updates(id): conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) firstname = request.json['firstname'] lastname = request.json['lastname'] query = "update details set firstname = '"+ firstname +"', lastname = '"+ lastname +"' Where NameID = '"+ id +"'" cur.execute(query) conn.commit() cur.close() output = {'firstname' : request.json['firstname'], 'lastname' : request.json['lastname'], 'Message': 'Success'} return jsonify({'result' : output})
def delete(id): conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) firstname = request.json['firstname'] lastname = request.json['lastname'] query = "DELETE from details Where NameID = '"+ id +"'" cur.execute() conn.commit() cur.close() output = {'firstname' : request.json['firstname'], 'lastname' : request.json['lastname'], 'Message': 'DELETED'} return jsonify({'result' : output})
def inst(): conn = mysql.connect() cur = conn.cursor(mysql.cursors.DictCursor) firstname = request.json['firstname'] lastname = request.json['lastname'] query = "insert into details (firstname, lastname) values ('"+ firstname +"', '"+ lastname +"')" cur.execute(query) conn.commit() cur.close() output = {'firstname' : request.json['firstname'], 'lastname' : request.json['lastname'], 'Message': 'Success'} return jsonify({'result' : output})
def get_price(price): try: conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute("select count(product_id) as prod_count from product where price <" +price) rows = cur.fetchall() res = jsonify(rows) return res except Exception as e: print(e) finally: cur.close() conn.close()
def get_quantity(quan): try: conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute("select product_id, product_name from product where quantity = " +quan) rows = cur.fetchall() res = jsonify(rows) return res except Exception as e: print(e) finally: cur.close() conn.close()
def list(): try: conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute("select product_id,product_name,quantity,price from product") rows = cur.fetchall() res = json.dumps(rows, cls=DecimalEncoder) return res except Exception as e: print(e) finally: cur.close() conn.close()
def userone(id): try: conn = mysql.connect() cur = conn.cursor(pymysql.cursors.DictCursor) cur.execute("SELECT * FROM FlaskMysql WHERE NAMEID =" + id) rows = cur.fetchall() resp = jsonify(rows) resp.status_code = 200 return resp except Exception as e: print(e) finally: cur.close() conn.close()