Added SQL functionality and tests