Added an "upsert" mechanism and associated unittests.

Upsert is a portmanteau for "update" and "insert". It allows a single
statement to either insert if the primary key is not presetn or update
if it is present.

The current implementation is MySQL specific and will return an error
for any other dialect. Support for this feature varies widely amongst
database vendors as it's not part of the SQL ansi standard. For MySQL,
we use the "ON DUPLICATE KEY UPDATE ..." suffix to insert statements.