Sqlite capi

Please review and merge this into 1.7.
It is required to fix bug #2270 and implements our own unified sqlite api that avoids that we use different sqlite library versions especially on Mac. Also fixes to make the tests running again.

Please
- Test if the strange sqlite fails go away with this patch on Mac (@guruz)
- Add a recent sqlite library to the build system especially on Mac
- review ( @ogoffart @guruz @danimo )
- Test test test.