Sql enhancement

Also fixed message type deserialization