Initial version of sql handling code