alot of this and the sqlite version of this file could be extracted out into a baseclass.