Throw exception on sql error, and add options for the random method