Improve SQL queries.

* Escape email addresses;
* Check repo-id validity in RPC;
* Escape some strings when storing them to SQLite.