Make a bit more Database Agnostic

Cahnge select function to a function that parametrizes the most common
SELECT statements, encapsulates column and table names correctly, and
automatically builds query parameters. Then replace all typed out
"SELECT ..." statements in the rest of the code with this function.