<commit_before>module TinyTds
  class Client

    @@default_query_options = {
      :as => :hash,
      :symbolize_keys => false,
      :cache_rows => true,
      :timezone => :local,
      :empty_sets => true
    }

    attr_reader :query_options

    class << self

      def default_query_options
        @@default_query_options
      end

      # Most, if not all, iconv encoding names can be found by ruby. Just in case, you can
      # overide this method to return a string name that Encoding.find would work with. Default
      # is to return the passed encoding.
      #
      def transpose_iconv_encoding(encoding)
        encoding
      end

    end


    def initialize(opts={})
      raise ArgumentError, 'missing :host option if no :dataserver given' if opts[:dataserver].to_s.empty? && opts[:host].to_s.empty?
      opts[:username] = parse_username(opts)
      @query_options = @@default_query_options.dup
      opts[:password] = opts[:password].to_s if opts[:password] && opts[:password].to_s.strip != ''
      opts[:appname] ||= 'TinyTds'
      opts[:tds_version] = tds_versions_setter(opts)
      opts[:login_timeout] ||= 60
      opts[:timeout] ||= 5
      opts[:encoding] = (opts[:encoding].nil? || opts[:encoding].downcase == 'utf8') ? 'UTF-8' : opts[:encoding].upcase
      opts[:port] ||= 1433
      opts[:dataserver] = "#{opts[:host]}:#{opts[:port]}" if opts[:dataserver].to_s.empty?
      connect(opts)
    end

    def tds_version_info
      info = TDS_VERSIONS_GETTERS[tds_version]
      "#{info[:name]} - #{info[:description]}" if info
    end

    def active?
      !closed? && !dead?
    end


    private

    def self.local_offset
      ::Time.local(2010).utc_offset.to_r / 86400
    end

    def parse_username(opts)
      username = opts[:username]
      return username if username.nil? || !opts[:azure] || !username.include?("@")
      user, domain = username.split("@")
      "#{user}@#{domain.split('.').first}"
    end

    def tds_versions_setter(opts={})
      v = opts[:tds_version] || ENV['TDSVER'] || '7.3'
      TDS_VERSIONS_SETTERS[v.to_s]
    end
<commit_msg>Use 7.1 as default till new data types land.<commit_after>module TinyTds
  class Client

    @@default_query_options = {
      :as => :hash,
      :symbolize_keys => false,
      :cache_rows => true,
      :timezone => :local,
      :empty_sets => true
    }

    attr_reader :query_options

    class << self

      def default_query_options
        @@default_query_options
      end

      # Most, if not all, iconv encoding names can be found by ruby. Just in case, you can
      # overide this method to return a string name that Encoding.find would work with. Default
      # is to return the passed encoding.
      #
      def transpose_iconv_encoding(encoding)
        encoding
      end

    end


    def initialize(opts={})
      raise ArgumentError, 'missing :host option if no :dataserver given' if opts[:dataserver].to_s.empty? && opts[:host].to_s.empty?
      opts[:username] = parse_username(opts)
      @query_options = @@default_query_options.dup
      opts[:password] = opts[:password].to_s if opts[:password] && opts[:password].to_s.strip != ''
      opts[:appname] ||= 'TinyTds'
      opts[:tds_version] = tds_versions_setter(opts)
      opts[:login_timeout] ||= 60
      opts[:timeout] ||= 5
      opts[:encoding] = (opts[:encoding].nil? || opts[:encoding].downcase == 'utf8') ? 'UTF-8' : opts[:encoding].upcase
      opts[:port] ||= 1433
      opts[:dataserver] = "#{opts[:host]}:#{opts[:port]}" if opts[:dataserver].to_s.empty?
      connect(opts)
    end

    def tds_version_info
      info = TDS_VERSIONS_GETTERS[tds_version]
      "#{info[:name]} - #{info[:description]}" if info
    end

    def active?
      !closed? && !dead?
    end


    private

    def self.local_offset
      ::Time.local(2010).utc_offset.to_r / 86400
    end

    def parse_username(opts)
      username = opts[:username]
      return username if username.nil? || !opts[:azure] || !username.include?("@")
      user, domain = username.split("@")
      "#{user}@#{domain.split('.').first}"
    end

    def tds_versions_setter(opts={})
      v = opts[:tds_version] || ENV['TDSVER'] || '7.1'
      TDS_VERSIONS_SETTERS[v.to_s]
    end

{'fraction_non_alphanumeric': 0.14093801555503183, 'fraction_numerical': 0.009898656610888523, 'mean_word_length': 2.875799086757991, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4786287', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1376, 'n_words': 314}