Class Sip::MySQLSipper
In: lib/sip/databases/mysql.rb
Parent: DBBase

Methods

Public Class methods

[Source]

# File lib/sip/databases/mysql.rb, line 5
    def initialize(args, sipper)
      super(args, sipper)
      @connection = Mysql::new @args['host'], @args['username'], @args['password'], @args['dbname'], @args['port']
    end

Public Instance methods

[Source]

# File lib/sip/databases/mysql.rb, line 48
    def close
      @connection.close
    end

[Source]

# File lib/sip/databases/mysql.rb, line 10
    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

[Source]

# File lib/sip/databases/mysql.rb, line 31
    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

[Source]

# File lib/sip/databases/mysql.rb, line 22
    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

[Validate]