Sqlight database working properly

Changes to sqlight database and changes in thread handling.
TODO need to fix the drawing math.