示例#1
0
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()
示例#2
0
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})
示例#3
0
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})
示例#4
0
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})
示例#5
0
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()
示例#6
0
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()
示例#7
0
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()
示例#8
0
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()