Sha256: e004dc8e86509ea9bec210739c5b98f9cbb32659d54dd4fd2d1313c1eb8b3729

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require "mysql"

module Sip
  class MySQLSipper < DBBase
    def initialize(args, sipper)
      super(args, sipper)
      @connection = Mysql::new @args['host'], @args['username'], @args['password'], @args['dbname'], @args['port']
    end
    
    def cmd_line_execute_string(select)
      opts = CmdOpts.new 
      opts.set 'N', 'B', 'C', 'q'
      opts['u'] = @args['username']
      opts['password'] = @args['password']
      opts['h'] = @args['host']
      opts['e'] = "'#{select}'"      
      opts['P'] = @args['port']
      path = `which mysql`
      opts.to_s(path.strip, @args['dbname'])
    end

    def query(q)
      @sipper.log "Running MySQL Query: #{q}"
      c = @connection.query(q)
      return nil if c.nil?
      results = []
      c.num_rows.times { results << c.fetch_row }
      results
    end

    def convert_to_hive_type(typename)
      case typename.split("(").first
        when "tinyint" then "TINYINT"
        when "smallint" then "MEDIUMINT"
        when "mediumint" then "INT"
        when "int" then "INT"
        when "bigint" then "BIGINT"
        when "decimal" then "FLOAT"
        when "numeric" then "DOUBLE"
        when "float" then "FLOAT"
        when "real" then "DOUBLE"
        when "double" then "DOUBLE"
        when "boolean" then "BOOLEAN"
        else "STRING"
      end
    end

    def close
      @connection.close
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sip-0.0.0 lib/sip/databases/mysql.rb