def update_userinv_row(update_input, rowid): # Updates a userinventory row using the row id (so duplicates aren't # affected). This will mostly be used for moving and checking out bottles arg = 'UPDATE userinventory SET ' for term in update_input: arg += term + ' = :' + term + ', ' arg = arg.rstrip(', ') arg += ' WHERE rowid = ' + str(rowid) inv_update = DatabaseManager() inv_update.db_execute(arg, update_input)
def update_winedata_row(update_input): # updates a specific row in a specified table # this function takes a list of the following format: # entry_input = [wine_id, upc, winery, region, # name, varietal, wtype, # vintage, msrp, value] terms = cleanup_dbinput(update_input) arg = 'UPDATE winedata SET ' for term in terms: arg += term + ' = :' + term + ', ' arg = arg.rstrip(', ') arg += ' WHERE wine_id = :wine_id' db_update = DatabaseManager() db_update.db_execute(arg, terms)
def drop_row(wine_id, rowid=None, table='userinventory'): # drops a row from the database, if for example it is # entered by mistake # this function only takes a wine_id input, which forces # the wine to be positively identified before it is # deleted # This also allows the table to be selected. By default, # the table is the user inventory (which is less dangerous) terms = [wine_id] arg = 'DELETE FROM ' + table + ' WHERE wine_id = ?' if rowid: arg += ' AND rowid = ?' terms.append(rowid) terms = tuple(terms) db_drop = DatabaseManager() db_drop.db_execute(arg, terms)
def enter_db(entry_input, table='userinventory', ret_id=False): # enters a wine into the database # this function takes a list of the following format: # entry_input = [wine_id, upc, winery, region, # name, varietal, wtype, # vintage, msrp, value] # it is critical that the list is complete, even if some # of the values are null db_enter = DatabaseManager() terms = cleanup_dbinput(entry_input) #arg = 'INSERT INTO ' + table + ' (upc, winery, region, name, varietal, wtype, vintage, msrp, value) VALUES (?,?,?,?,?,?,?,?,?)' arg = 'INSERT INTO ' + table + ' (' values = '(' for term in terms: arg += term + ', ' values += ':' + term + ', ' values = values.rstrip(', ') + ')' arg = arg.rstrip(', ') + ') VALUES ' + values return db_enter.db_execute(arg, terms, ret_id)