plugins/report/app/models/connect.rb in admin-sys-1.0.2 vs plugins/report/app/models/connect.rb in admin-sys-1.1.0

- old
+ new

@@ -1,46 +1,46 @@ -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 +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