def countAthletes(self): connection = Database.connect(self) result = connection.execute("SELECT count(name) as 'athletes_count' FROM athlete") result = result.fetchone() return result['athletes_count']
def getExercisesByAthleteName(self, athleteName): connection = Database.connect(self) result = connection.execute("SELECT * FROM exercise WHERE athleteName = :athl_name", {"athl_name" :athleteName}) return result.fetchall()
def countAthletes(self): connection = Database.connect(self) result = connection.execute( "SELECT count(name) as 'athletes_count' FROM athlete") result = result.fetchone() return result['athletes_count']
def store(self, exercise): connection = Database.connect(self) connection.execute("INSERT INTO exercise VALUES (null, :athleteName, :date, :avgHeartRate)", {"athleteName":exercise._athleteName, "date":exercise._date, "avgHeartRate": exercise._averageHeartRate}) connection.commit() connection.close()
def deletePushup(self, exerciseId): connection = Database.connect(self) connection.execute("DELETE FROM pushup WHERE exerciseId=:id ", {"id": exerciseId}) connection.execute("DELETE FROM exercise WHERE id=:id",{"id": exerciseId}) connection.commit() connection.close()
def delete(self, athleteName): database = Database.connect(self) pushupDatabase = Pushup_Foundation() pushupDatabase.deletePushupsByAthlete(athleteName) database.execute("DELETE FROM athlete WHERE name=:name", {"name": athleteName}) database.commit() database.close()
def deletePushup(self, exerciseId): connection = Database.connect(self) connection.execute("DELETE FROM pushup WHERE exerciseId=:id ", {"id": exerciseId}) connection.execute("DELETE FROM exercise WHERE id=:id", {"id": exerciseId}) connection.commit() connection.close()
def getAthletes(self): connection = Database.connect(self) result = connection.execute("SELECT * FROM athlete") result = result.fetchall() athletesList = [] for row in result: athlete = self._createAthleteFromRow(row) athletesList.append(athlete) return athletesList
def getAthletes(self): connection = Database.connect(self) result = connection.execute("SELECT * FROM athlete") result = result.fetchall() athletesList = [] for row in result : athlete = self._createAthleteFromRow(row) athletesList.append(athlete) return athletesList
def store(self, athlete): if self._nameAlreadyExists(athlete._name): print "Error: Name '" + athlete._name + "' already taken.\n" else: database = Database.connect(self) database.execute("INSERT INTO athlete VALUES (:name, :surname, :sex, :birthDate, :height, :mass)", {"name": athlete._name, "surname": athlete._surname, "sex":athlete._sex, "birthDate":athlete._birthDate, "height":athlete._height, "mass":athlete._mass}) database.commit() database.close()
def _nameAlreadyExists(self, name): connection = Database.connect(self) cursor = connection.execute("SELECT * FROM athlete WHERE name==:name", {"name": name}) result = cursor.fetchall() if len(result) == 0: nameAlreadyExists = False else: nameAlreadyExists = True cursor.close() return nameAlreadyExists
def getAllPushups(self): connection = Database.connect(self) cursor = connection.execute("SELECT * FROM pushup inner join exercise on exerciseId=id") pushupRows = cursor.fetchall() #keys = pushupRows[0].keys() # useful to check row keys. pushupsList = [] for row in pushupRows: pushupObj = self._getPushupFromRow(row) pushupsList.append(pushupObj) return pushupsList
def getPushupsByAthlete(self, athleteName): connection = Database.connect(self) cursor = connection.execute("SELECT * FROM pushup inner join exercise on " +\ "exerciseId=id WHERE athleteName = :name ORDER BY date", {"name":athleteName}) pushupsList = [] pushupRows = cursor.fetchall() for row in pushupRows: pushupObj = self._getPushupFromRow(row) pushupsList.append(pushupObj) return pushupsList
def getAllPushups(self): connection = Database.connect(self) cursor = connection.execute( "SELECT * FROM pushup inner join exercise on exerciseId=id") pushupRows = cursor.fetchall() #keys = pushupRows[0].keys() # useful to check row keys. pushupsList = [] for row in pushupRows: pushupObj = self._getPushupFromRow(row) pushupsList.append(pushupObj) return pushupsList
def store(self, pushup): connection = Database.connect(self) connection.execute("INSERT INTO exercise VALUES (null, :athleteName, :date, :avgHeartRate)", {"athleteName":pushup._athleteName, "date":pushup._date, "avgHeartRate": pushup._averageHeartRate}) cursor = connection.execute("SELECT max(id) as lastId FROM exercise") exerciseId = cursor.fetchone()["lastId"] connection.execute("INSERT INTO pushup VALUES(:exerciseId, :repetitions, :series)", {"exerciseId":exerciseId, "repetitions":pushup._repetitions, "series":pushup._series}) connection.commit() connection.close()
def load(self, athleteName): connection = Database.connect(self) result = connection.execute("SELECT * FROM athlete WHERE name=:searchParam", {"searchParam" :athleteName}) result = result.fetchall() resultLength = len(result) if resultLength == 1: athlete = self._createAthleteFromRow(result[0]) elif resultLength == 0: print "Error. No profile found for " + "'" + athleteName + "'" athlete = False elif resultLength > 1: print "Database corrupted. More than one tuple for the same Primary Key" athlete = False return athlete
def store(self, athlete): if self._nameAlreadyExists(athlete._name): print "Error: Name '" + athlete._name + "' already taken.\n" else: database = Database.connect(self) database.execute( "INSERT INTO athlete VALUES (:name, :surname, :sex, :birthDate, :height, :mass)", { "name": athlete._name, "surname": athlete._surname, "sex": athlete._sex, "birthDate": athlete._birthDate, "height": athlete._height, "mass": athlete._mass }) database.commit() database.close()
def load(self, athleteName): connection = Database.connect(self) result = connection.execute( "SELECT * FROM athlete WHERE name=:searchParam", {"searchParam": athleteName}) result = result.fetchall() resultLength = len(result) if resultLength == 1: athlete = self._createAthleteFromRow(result[0]) elif resultLength == 0: print "Error. No profile found for " + "'" + athleteName + "'" athlete = False elif resultLength > 1: print "Database corrupted. More than one tuple for the same Primary Key" athlete = False return athlete
def store(self, pushup): connection = Database.connect(self) connection.execute( "INSERT INTO exercise VALUES (null, :athleteName, :date, :avgHeartRate)", { "athleteName": pushup._athleteName, "date": pushup._date, "avgHeartRate": pushup._averageHeartRate }) cursor = connection.execute("SELECT max(id) as lastId FROM exercise") exerciseId = cursor.fetchone()["lastId"] connection.execute( "INSERT INTO pushup VALUES(:exerciseId, :repetitions, :series)", { "exerciseId": exerciseId, "repetitions": pushup._repetitions, "series": pushup._series }) connection.commit() connection.close()
def __init__(self): Database.__init__(self)
def __init__(self): Database.__init__(self) pass