コード例 #1
0
def insert_category():
    r = request.form

    cat_name = "'" + r['cat_name'] + "'"

    columns = '(name)'

    data = cat_name
    query = db.insert(data, 'category', columns)
    db.run_query(query, default_params)
    return ''
コード例 #2
0
def insert_note():
    r = request.form

    title = "'" + r['title'] + "'"
    data = "'" + r['data'] + "'"
    cat_id = "'" + r['cat_id'] + "'"
    deleted = "'" + '0' + "'"

    columns = '(title, data, cat_id, deleted)'

    data = ','.join([title, data, cat_id, deleted])
    query = db.insert(data, 'note', columns)
    db.run_query(query, default_params)
    return ''
コード例 #3
0
def foo():
    query = '''
        SELECT UnitPrice, Quantity FROM invoice_items;
    '''
    results = run_query(query)
    sum_ = 0
    for price, quantity in results:
        sum_ += price * quantity

    return str(sum_)
コード例 #4
0
def customers():
    query = '''
    SELECT * FROM customers
    '''

    country = request.args.get('country')
    if country:
        param = f" WHERE Country = '{country}'"
        query += param

    order = request.args.get('ordering')
    if order:
        param = f" ORDER BY {ordering(order)}"
        query += param

    query += ';'
    return str(run_query(query))
コード例 #5
0
ファイル: main.py プロジェクト: novichuk/PythonLessons
def customers():
    query = '''
    SELECT * FROM customers
    '''

    country = request.args.get('country')
    if country:
        param = f"WHERE Country ='{country}'"
        query += param

    filter_args = request.args.get('filter')
    if filter_args:
        param = f" AND {filter_and(filter_args)}"
        query += param

    order = request.args.get('ordering')
    if order:
        param = f" ORDER BY {ordering(order)}"
        query += param

    query += ';'
    print(query)
    return str(run_query(query))
コード例 #6
0
def delete_note(note_id):
    query = db.update('note', 'deleted', 1, 'id = ' + note_id)
    db.run_query(query, default_params)
    return ''
コード例 #7
0
def get_note(note_id):
    query = db.select("*", 'note', 'deleted = 0 and id = ' + note_id)
    result = db.run_query(query, default_params, select=True)
    return {'data': result}
コード例 #8
0
def get_notes():
    query = db.select("*", 'note', 'deleted = 0')
    result = db.run_query(query, default_params, select=True)
    return {'data': result}
コード例 #9
0
def get_categories():
    query = db.select("*", 'category')
    result = db.run_query(query, default_params, select=True)
    return {'data': result}
コード例 #10
0
def foo2():
    query = '''
        SELECT SUM(UnitPrice * Quantity) FROM invoice_items;
    '''
    return str(run_query(query))
コード例 #11
0
def employees():
    query = '''
        SELECT * FROM employees;
    '''
    return str(run_query(query))