Class Sip::DBBase
In: lib/sip/databases/dbbase.rb
Parent: Object

Methods

Attributes

args  [R] 

Public Class methods

[Source]

# File lib/sip/databases/dbbase.rb, line 5
    def self.make_interface(type, args, sipper)
      if type == 'mysql'
        require 'sip/databases/mysql'
        MySQLSipper.new args, sipper
      else
        raise UnsupportedDatabaseType, "DB type #{type.to_s} not supported."
      end
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 14
    def initialize(args, sipper)
      @args = args
      @sipper = sipper
    end

Public Instance methods

[Source]

# File lib/sip/databases/dbbase.rb, line 37
    def columns(table)
      query("DESCRIBE #{table}").map { |col|
        col.slice(0,2)
      }
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 47
    def generate_command(tableconf, first=nil, last=nil)
      select = "SELECT #{columns(tableconf['tablename']).map { |k,v| k }.join(',')} FROM #{tableconf['tablename']}"
      wheres = []
      wheres << "#{tableconf['incremental_index']} >= #{first}" if not first.nil?
      wheres << "#{tableconf['incremental_index']} <= #{last}" if not last.nil?
      select += " WHERE #{wheres.join(" AND ")}" if wheres.length > 0
      cmd_line_execute_string select
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 27
    def get_column_max(tablename, field)
      query("SELECT max(#{field}) FROM #{tablename}").first.first.to_i
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 31
    def hive_columns(table)
      columns(table).map { |name, type|
        [name, convert_to_hive_type(type)]
      }
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 43
    def order_column_list(table, cols)
      columns(table).map { |k,v| k }.select { |c| cols.include? c }
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 23
    def rowcount(table)
      query('SELECT count(1) FROM #{table}').first.first.to_i
    end

[Source]

# File lib/sip/databases/dbbase.rb, line 19
    def tables
      query('SHOW tables')
    end

[Validate]