Class: Treport::Db
- Inherits:
-
Object
- Object
- Treport::Db
- Defined in:
- lib/treport/db.rb
Constant Summary collapse
- AdapterType =
{ Mysql: "mysql2", PostgreSQL: "postgresql", Sqlserver: "sqlserver", Oracle: "oracle" }
Class Method Summary collapse
- .adapter_options ⇒ Object
- .mysql_query(conectstr, sql) ⇒ Object
- .oracle_query(conectstr, sql) ⇒ Object
- .sqlserver_query(conectstr, sql) ⇒ Object
Class Method Details
.adapter_options ⇒ Object
10 11 12 |
# File 'lib/treport/db.rb', line 10 def self. [["Mysql", AdapterType[:Mysql]], ["PostgreSQL", AdapterType[:PostgreSQL]], ["Sqlserver", AdapterType[:Sqlserver]], ["Oracle", AdapterType[:Oracle]]] end |
.mysql_query(conectstr, sql) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/treport/db.rb', line 31 def self.mysql_query(conectstr, sql) result = [] Mysql2::Client.new(conectstr).query(sql).each do |r| result << r end result end |
.oracle_query(conectstr, sql) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/treport/db.rb', line 14 def self.oracle_query(conectstr, sql) require 'ruby-oci8' result = [] conn = OCI8.new(conectstr[:username], conectstr[:password], "#{conectstr[:host]}:#{conectstr[:port]}/#{conectstr[:database]}") cursor = conn.parse(sql) cursor.exec while r = cursor.fetch_hash() r.each do |n, v| unless v r[n] = "其他" end end result << r end result end |
.sqlserver_query(conectstr, sql) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/treport/db.rb', line 39 def self.sqlserver_query(conectstr, sql) connstr = {} conectstr.each { |k, v| connstr[k.to_sym]=v } result = [] TinyTds::Client.new(connstr).execute(sql).each do |row| result << row end result end |