Moving and naming SQL statements

This commit is contained in:
Jonathan Ervine 2020-12-11 10:08:14 +08:00
parent ec7ff3e3e1
commit 4d04ce697f

View File

@ -51,8 +51,8 @@ def convenorAddClubResult():
@routes.route('/convenor/teamAdd') @routes.route('/convenor/teamAdd')
def convenorAddTeam(): def convenorAddTeam():
sql = "SELECT club FROM _clubTeams GROUP BY club ORDER BY club" clubs_query = "SELECT club FROM _clubTeams GROUP BY club ORDER BY club"
clubs = sql_read(sql) clubs = sql_read(clubs_query)
form = addTeamForm() form = addTeamForm()
return render_template('_convenorTeamAdd.html', data=clubs, form=form) return render_template('_convenorTeamAdd.html', data=clubs, form=form)
@ -61,14 +61,15 @@ def convenorAddTeamResult():
try: try:
_club = request.form['clubName'] _club = request.form['clubName']
_team = request.form['teamName'] _team = request.form['teamName']
clubTeam_lookup = "SELECT club, team FROM _clubTeams WHERE club='" + _club + "' AND team='" + _team + "'"
clubTeam_create = "INSERT INTO _clubTeams (club, team) VALUES ('" + _club + "', '" + _team + "')"
if _club and _team and request.method == 'POST': if _club and _team and request.method == 'POST':
sql = "SELECT club, team FROM _clubTeams WHERE club='" + _club + "' AND team='" + _team + "'" sql =
teamExist = sql_read(sql) teamExist = sql_read(clubTeam_lookup)
if teamExist: if teamExist:
return 'Team already exists in the database' return 'Team already exists in the database'
else: else:
sql2 = "INSERT INTO _clubTeams (club, team) VALUES ('" + _club + "', '" + _team + "')" sql_write(clubTeam_create)
sql_write(sql2)
return render_template('_convenorTeamAddResults.html', club=_club, team=_team) return render_template('_convenorTeamAddResults.html', club=_club, team=_team)
except Exception as e: except Exception as e:
print(e) print(e)