SQL mapper: tweaks

Hi,
this pull request suggests 2 changes:

- `beforeinsert` and `beforeupdate` hooks to be called at the very beginning of the `insert()` and `update()` methods (cf. issue #525) otherwise there's no chance to modify the object before update.
- `afterinsert` and `afterupdate` hooks to be called only when INSERT/UPDATE statements actually occured. Same thing with the calculation of the last inserted id `_id`.