Viktor/sqlfunctions

This is a massive rewrite of a lot of stuff, but it will let us lock down the database a lot better.

I've tested everything affected afaik, but I could have missed something. We need to write real integration tests.
You mean `select * from function` vs `select function`? I didn't realize you can do it without the `*`. What's the difference between the two? Should we make all of the function calls not use the `*`?