Coding against databases

From 22112
Jump to navigation Jump to search
Previous: MySQL Next: Computer design

Material for the lesson

Note: The powerpoint has been updated with new library and transactions, but not the video.
Video: Using Python with MySQL
Powerpoint: Coding with Databases
Video: Exercises

Exercises

Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are "complete" for the time period they were collected in. Specifically, all children's parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).
The programs should run on the server pupil1, not your own machine.
The mysql connect call looks like this.
cnx = mysql.connector.connect(user='DTUusername', passwd='YOUR_PASSWORD', db='DTUusername', host='localhost')
You can find your password in the .my.cnf file in your home.
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.
Note, use this python: /home/ctools/anaconda3_2021.11/bin/python3

1)
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).

2)
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.

If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.