CS1116/CS5018 Lab 3
Before you start on this week's work, you have the opportunity to check the first part of last week's work (where you revised
lengths.py to include validation of user input).
This is an experimental facility, which gives rough-and-ready feedback. It is not used for grading.
Fix problems in your private study time. For now, move on to this week's work.
Step 1: Create a database
public_html/cgi-bin directory, create a new directory called
(no spaces, all in lowercase!!!!!!). Change its permissions! Place your work for this lab sheet into
this new directory.
Take a copy of the following file (right-click on each link and choose 'Save link as…')
and save it in your
Do not modify
eurovision.sql in any way.
As you did in CS1106/CS5021, use
DBeaver to login to
the MySQL DBMS on cs1.ucc.ie.
When you are connected to the DBMS, still using DBeaver, right-click in the SQL editor
and choose 'Load SQL Script' from the menu. Use the file chooser to open
eurovision.sql file that you copied above.
If all of that worked OK, then you now have a new database table called
winners, which has
the following columns:
If you want to check, then type:
select * from winners;
You should see a table of Eurovision winning songs.
You can now close down DBeaver.
Step 2: Write a program
In a file called
eurovision.py in your
lab3 directory, write a Python
server-side program, as follows.
The program implements a self-processing page:
- The program initially displays a form, which has a textfield, which allow the user to enter a country.
- On submit, the program takes the country that the user entered and searches the database for all eurovision winners from that country. It displays the form again and, just below the form, it displays an HTML table that displays the data you retrieved from the database.
In case the previous paragraph is not clear, you can run mine to see what yours should do:
Step 3: Improve your program
When your self-processing page is working, improve your program. You may do as few or as many of these as you wish:
- Make the form sticky.
- If the user's country wasn't in the database, include an error message.
- Replace the textfield by a menu (using HTML
select). The program should create the menu options from countries that it retrieves from the database.
- Add to the form a textfield for points. Treat country and points conjunctively.
In other words,
- if the user enters a country but no points, search for winners from that country;
- if the user enters points but no country, search for winners who achieved at least that many points;
- if the user enters a country and points, search for winners from that country who achieved at least that many points.
There is no formal submission of this week's exercises. However, for my records, I will run a program that checks to see whether you have done the work or not.