Class: Sip::MySQLSipper
Instance Attribute Summary
Attributes inherited from DBBase
#args
Instance Method Summary
collapse
Methods inherited from DBBase
#columns, #generate_command, #get_column_max, #hive_columns, make_interface, #order_column_list, #rowcount, #tables
Constructor Details
#initialize(args, sipper) ⇒ MySQLSipper
Returns a new instance of MySQLSipper.
5
6
7
8
|
# 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
|
Instance Method Details
#close ⇒ Object
48
49
50
|
# File 'lib/sip/databases/mysql.rb', line 48
def close
@connection.close
end
|
#cmd_line_execute_string(select) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# 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
|
#convert_to_hive_type(typename) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# 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
|
#query(q) ⇒ Object
22
23
24
25
26
27
28
29
|
# 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
|