Exemplo n.º 1
0
def insert_data():
    with open(r"resource/test.json", 'r') as load_f:
        load_dict = json.load(load_f)
        cursor = conn.cursor()
        for prov in load_dict:
            cursor.execute(
                'insert into tb_province(provid,provname,state) values(%s,%s,\'1\')',
                [prov["code"], prov["name"]])
            if len(prov["sub"]) > 0:
                for city in prov["sub"]:
                    cursor.execute(
                        'insert into tb_city(cityid,cityname,provid,provname,state) values(%s,%s,%s,%s,\'1\')',
                        [
                            city["code"], city["name"], prov["code"],
                            prov["name"]
                        ])
                    if 'sub' in city and len(city["sub"]) > 0:
                        for country in city["sub"]:
                            cursor.execute(
                                'insert into tb_county(countyid,countyname,cityid,cityname,state) values(%s,%s,%s,%s,\'1\')',
                                [
                                    country["code"], country["name"],
                                    city["code"], city["name"]
                                ])
        conn.commit()
        cursor.close()
    return 'success'
Exemplo n.º 2
0
def test():
    cursor = conn.cursor()
    cursor.execute('insert into test(name) values(%s)', ['niu'])
    conn.commit()
    print(cursor.rowcount)
    cursor.close()
    return 'success'
Exemplo n.º 3
0
def petition():
    cur = conn.cursor()

    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        email = request.form['email']
        story = request.form.get('story')

        mp.people_set(email, {
            '$first_name'    : first_name,
            '$last_name'     : last_name,
            '$email'         : email,
            'story'          : story
        })

        mp.track(email, "Signed Petition");

        cur.execute("INSERT INTO signature (first_name, last_name, email, story) VALUES (%s, %s, %s, %s);", (first_name, last_name, email, story))


    cur.execute("SELECT first_name, last_name FROM signature;")
    results = cur.fetchall()

    signatures = []
    for signature in results:
        signatures.append(signature[0] + ' ' + signature[1])

    cur.close()
    conn.commit()
    return jsonify({"results": signatures})
Exemplo n.º 4
0
def index(name=None):
    cursor = conn.cursor()
    cursor.execute("select id,title,code,`table` from tb_table")
    value = cursor.fetchall()
    print('-----------------')
    print(value)
    cursor.close()
    return render_template('index.html', data=value)
Exemplo n.º 5
0
def delete():
    id = request.args.get('id')
    print('................')
    print(id)
    cursor = conn.cursor()
    cursor.execute("delete from tb_table where id=%s", [id])
    row = cursor.rowcount
    conn.commit()
    cursor.close()
    return str(row)
def delete_patient():
    if session.get('username'):
        if session.get('usertype') == "rde":
            pform = GetPatientId()
            if pform.validate_on_submit():
                ssn = pform.patientid.data
                cursor = conn.cursor(buffered=True)
                cursor.execute(
                    """SELECT (`*`) FROM `patient` WHERE `ws_ssn` LIKE '{}'""".
                    format(ssn))
                if cursor.rowcount > 0:
                    return redirect(url_for('fetch_To_delete', patientid=ssn))
                else:
                    flash("Patient Not Found")
                    return redirect(url_for('delete_patient'))
            return render_template("delete_patient.html", pform=pform)
    return redirect("/login")
Exemplo n.º 7
0
import sqlalchemy
import psycopg2
from application import db, conn, bcrypt
from models import Users, Paths, Checkpoints, Interactions
from config import Config

# Getting a cursor object from database connection
# It will be used to execute PSQL queries
cursor = conn.cursor()


class Database():
    # Checking for duplicate values in a table
    def check_duplicate(tablename, columnName, value):
        # Developing the query to get from the table
        query = "SELECT * FROM %s WHERE %s = '%s'" % (tablename, columnName,
                                                      value)

        try:
            # Executing the query
            cursor.execute(query)

            # Finding out if it exists in the table
            exists = cursor.fetchone() is not None

            # Returning if the entry exists or not
            return exists
        except Exception as error:
            return "Error! %s" % error

    # Function to get id of a user