void InventoryDAOMySQL::updateInventory(const Inventory &inventory) { MySQLManager::ConnectionHolder ch(MySQLManager::getInstance()); std::unique_ptr<sql::PreparedStatement> ps(ch.conn->prepareStatement(UPDATE_INVENTORY)); ps->setInt(1, inventory.getUserId()); ps->setInt(2, inventory.getFoodId()); ps->setString(3, inventory.getUseBy()); ps->setInt(4, inventory.getId()); ps->executeUpdate(); }
void InventoryDAOMySQL::addInventory(Inventory &inventory, int &newId) { MySQLManager::ConnectionHolder ch(MySQLManager::getInstance()); std::unique_ptr<sql::PreparedStatement> ps(ch.conn->prepareStatement(ADD_INVENTORY)); ps->setInt(1, inventory.getUserId()); ps->setInt(2, inventory.getFoodId()); ps->setString(3, inventory.getUseBy()); ps->execute(); newId = MySQLManager::lastGeneratedId(ch.conn); }