Пример #1
0
def set_notification_settings(projectId, deviceId, weeks):
    if not notification_settings_exist():
        cmd = "INSERT INTO notification_settings (project_id, device_id, reminder_weeks) VALUES (?, ?, ?)"
    else:
        cmd = "UPDATE notification_settings SET project_id = ?, device_id = ?, reminder_weeks = ?"

    do_command(cmd, [projectId, deviceId, weeks])
Пример #2
0
def owner_is_active(owner_name):
    rslt = do_command('select active from owner where owner_name = ?',
                      [owner_name])
    if len(rslt) > 0:
        return rslt[0]['active'] != 0
    else:
        return False
Пример #3
0
def get_owner_id_by_name(owner_name):
    rslt = do_command("select owner_id from owner where owner_name = ?",
                      [owner_name])
    if len(rslt) > 0:
        return rslt[0]['owner_id']
    else:
        return None
Пример #4
0
def get_measurements_for_location(location):
    rslt = do_command(
        'select * from measurement where measurement_location = ?', [location])
    if len(rslt) > 0:
        return rslt
    else:
        return None
Пример #5
0
def get_notification_settings():
    if notification_settings_exist():
        cmd = "SELECT project_id, device_id, reminder_weeks FROM notification_settings"
        rtVal = do_command(cmd)

        return rtVal[0]
    return None
Пример #6
0
def get_categories_for_area(area):
    rslt = do_command(
        'select * from category inner join category_area on category_area.category_id=category.category_id where area_id = ?',
        [area])
    if len(rslt) > 0:
        return rslt
    else:
        return None
Пример #7
0
def get_owner_id_for_ticket(ticket):
    rslt = do_command(
        '''select owner
            from ticket
            where ticket.value = ?
        ''', [ticket])
    if len(rslt) > 0:
        return rslt[0]['owner']
    else:
        return None
Пример #8
0
def get_average_measurement_for_area(area):
    rslt = do_command(
        'select measurement.value from measurement inner join location on measurement_location=location.location_id where location_area = ?',
        [area])
    if len(rslt) > 0:
        ret_val = 0
        for entry in rslt:
            ret_val += entry['value']
        return ret_val / (len(rslt))
    else:
        return None
Пример #9
0
def do_drop():
    drop_owner = """drop table if exists owner"""
    do_command(drop_owner)
    drop_loan = """drop table if exists loan"""
    do_command(drop_loan)
    drop_ticket = """drop table if exists ticket"""
    do_command(drop_ticket)
Пример #10
0
def do_create():
    cmd_owner = """
        create table owner
        (
          owner_id integer PRIMARY KEY autoincrement,
          owner_name varchar(30) UNIQUE ,
          active INTEGER DEFAULT 1
        )
    """
    do_command(cmd_owner)

    cmd_loan = """
        create table loan
        (
          loan_id integer primary key autoincrement,
          owner REFERENCES owner(owner_id),
          initial_balance real,
          number_of_months integer,
          annual_rate real,
          monthly_payment real
        )
    """
    do_command(cmd_loan)

    cmd_ticket = """
        create table ticket (
          owner REFERENCES owner(owner_id),
          value text UNIQUE,
          expires TIMESTAMP
        )
    """
    do_command(cmd_ticket)
Пример #11
0
def get_loan_for_loan_id(loan_id):
    rslt = do_command('select * from loan where loan_id = ?', [loan_id])
    if len(rslt) > 0:
        return rslt[0]
    else:
        return None
Пример #12
0
def get_loan_ids_for_owner(owner_id):
    rslt = do_command('select loan_id from loan where owner = ?', [owner_id])
    return rslt
Пример #13
0
def get_grocery_name(upc):
    cmd = "SELECT name FROM grocery WHERE upc = ?"
    rtVal = do_command(cmd, [upc])

    return bool(len(rtVal))
Пример #14
0
def notification_settings_exist():
    cmd = "SELECT id FROM notification_settings"
    rtVal = do_command(cmd)

    return bool(len(rtVal))
Пример #15
0
def get_all_areas():
    rslt = do_command('select * from area', )
    if len(rslt) > 0:
        return rslt
    else:
        return None
Пример #16
0
def get_locations_for_area(area):
    rslt = do_command('select * from location where location_area = ?', [area])
    if len(rslt) > 0:
        return rslt
    else:
        return None