Replace type_ptr by shared_ptr and solve some issues

Replace type_ptr by shared_ptr that can be easily replaced by boost::shared_ptr

Solve some issues encountered using sqlite3 backend

Not tested with any other backend