test_db: use returned id rather than assuming 1

In case the tests are being run without re-creating the tables
for each test, we should use the returned job_id value rather
than assuming it will be 1.
DB: correct documentation for add_job method

It returns the job identifier rather than nothing.
DB: prepare for usage with MySQL

Unfortunately DBAPI fails to standardize the "paramstyle" and so
we need to use %s rather than ? with MySQL.  Also when we are
locking the tables we cannot use subqueries (without additional
locking) so replace the query using a subquery with an
equivalent simple query.
DB: capitalize WHERE SQL keyword
SQLite: use custom cursor class for compatability

This class converts format style placeholders (%s) into question
marks in SQL queries being executed.
DB: use explicit test for arguments being None

This is to prevent this case being confused with the case of the
arguments being given but having false values (e.g. zero).
DB: avoid use of "magic" string "NULL"

We can use empty tuple as the default value, allowing us to
accept None as another non-default value.
test_db: check location-only form of set_location

Also check that the location wasn't changed when just changing
the foreign ID.