Initial SQL support working

Fixed issues with inserting messages