Sha256: 18da42ab9b8855a7f1db7efab0d00ef47789382e7b67176347ed7dd927b3e894
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
class Connect < ActiveRecord::Base has_many :reports AdapterType={ Mysql: "mysql2", PostgreSQL: "postgresql", Oracle: "oracle" } def self.adapter_options [["Mysql", AdapterType[:Mysql]], ["PostgreSQL", AdapterType[:PostgreSQL]], ["Oracle", AdapterType[:Oracle]]] end def exec(sql) result = [] if (self.adapter==AdapterType[:Oracle]) require 'ruby-oci8' conn = OCI8.new(self.username, self.password, "#{self.host}:#{self.port}/#{self.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 elsif (self.adapter==AdapterType[:Mysql]) Mysql2::Client.new(self.serializable_hash).query(sql).each do |r| result << r end end return result end def self.connect_options Connect.all.map { |c| [c.name, c.id] } end def adapter_name return "Mysql" if self.adapter == AdapterType[:Mysql] return "PostgreSQL" if self.adapter == AdapterType[:PostgreSQL] return "Oracle" if self.adapter == AdapterType[:Oracle] end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
admin-sys-1.0.2 | plugins/report/app/models/connect.rb |
admin-sys-1.0.1 | plugins/report/app/models/connect.rb |
admin-sys-1.0.0 | plugins/report/app/models/connect.rb |