April 2018
Beginner
340 pages
7h 54m
English
A select statement needs to know the table being read and the fields which the user wants returned. The basic syntax is as follows:
SELECT field1, field2 FROM table;
So, to read the users from our users table, we can do the following:
SELECT username, real_name from users;
Again, as we will be doing this repeatedly, writing a function that will do it for us is a good idea.
Add the following to database.py:
def get_all_users(): sql = "SELECT username, real_name FROM users" params = [] return perform_select(sql, params)
Here, we provide the basic select statement as the sql variable and an empty list as the params variable, since we do not need to include any user-supplied data.
Once again, everything which ...