Beispiel #1
0
def first_purchase(recv_wrapper, seqnum):
    # construct a db command
    whnum = recv_wrapper.get_data().arrived[0].whnum
    product_id = recv_wrapper.get_data().arrived[0].things[0].id
    product_desc = recv_wrapper.get_data().arrived[0].things[0].description
    product_count = recv_wrapper.get_data().arrived[0].things[0].count

    db_command1 = 'INSERT INTO miniamazon_app_product(product_id, name, description, price, ' + \
        'storage) VALUES(' + str(product_id) + ', \'' + product_desc + \
        '\', \'' + product_desc + '\', ' + str(50) + ', ' + str(product_count) + ')' + \
        ' ON CONFLICT DO NOTHING'
    db_command2 = 'INSERT INTO miniamazon_app_product_warehouse(product_id, warehouse_id) VALUES(' + \
        str(product_id) + ', ' + str(whnum) + ')' + ' ON CONFLICT DO NOTHING'
    db_command3 = 'INSERT INTO miniamazon_app_localstorage(storage, warehouse_id) VALUES(' + str(product_count) + \
        ', ' + str(whnum) + ') ON CONFLICT DO NOTHING RETURNING local_storage_id'
    # update database
    db_interface = DBInterface(cfg.db_name, cfg.db_user, cfg.db_password,
                               cfg.db_host, cfg.db_port)
    db_interface.setup_excecute_and_close(db_command1)
    db_interface.setup_excecute_and_close(db_command2)
    db_interface.setup()
    db_interface.execute(db_command3)
    local_storage_id = db_interface.cursor.fetchone()[0]
    db_interface.close()
    db_command4 = 'INSERT INTO miniamazon_app_localstorage_product(localstorage_id, product_id) ' + \
        'VALUES('+ str(local_storage_id) + ', ' + str(product_id) + ') ON CONFLICT DO NOTHING'
    db_interface.setup_excecute_and_close(db_command4)
Beispiel #2
0
def get_truckid_from_sql(orderid, verbose=True):
    db_interface = DBInterface(cfg.db_name, cfg.db_user, cfg.db_password,
                               cfg.db_host, cfg.db_port)
    db_command = 'SELECT truck_id FROM miniamazon_app_ordercollection WHERE order_collection_id = ' + str(
        orderid)
    db_interface.setup()
    db_interface.execute(db_command, verbose)
    truck_id = db_interface.cursor.fetchone()[0]
    db_interface.close()
    return truck_id