Improve SQL queries.

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