refactor doctype to make it thread safe
refactor for webnotes.conn.sql