fix bugs in sqlite adapter

The sqlite adapter was building wrong sql statements because it didn't consider all possible cases.These Bugs have been fixed.