Properly do sqlite3 and postgres detection

A) Undo my changes
B) Use WITH_LIB* defines as found already in the code
C) Add a toggle for sqlite too