require 'tiny_tds'
def client
client = TinyTds::Client.new username: 'user', password: 'pass', host: '192.168.4.4'
client.execute('use database').do
client
end
def services(id)
out = []
client.execute('exec GetServiceByServiceGroup @ServiceGroup = %s' % id).each(:symbolize_keys => true) do |s|
out << {:value => s[:ServiceName] + ' <i>(' + s[:ServiceID].to_s + ')</i>',
:child => operational_services(s[:ServiceID])}
end
out
end
def operational_services(id)
out = []
client.execute('exec GetOperationalServiceByService @Service = %s' % id).each(:symbolize_keys => true) do |os|
out << {:value => os[:OperationalServiceName] + ' <i>(' + os[:OperationalServiceID].to_s + ')<i>'}
end
out
end
out = []
client.execute('exec GetServiceGroupByDirection @Direction = 50').each(:symbolize_keys => true) do |service_group|
out << {:value => service_group[:ServiceGroupName] + ' <i>(' + service_group[:ServiceGroupID].to_s + ')</i>',
:child => services(service_group[:ServiceGroupID])}
end
out
我接受错误:
test.irb:28: [BUG] Segmentation fault at 0x0000000000000e
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
我想从数据库构建树级别的树,但tiny_tds会返回sg =(为什么? 我写函数“client”来清除当前返回值时的其他连接。其他tiny_tds说'尝试启动一个新的Adaptive Server操作,结果待处理(TinyTds :: Error)'
我哪里错了?
答案 0 :(得分:0)
我不知道为什么,但这些工作
def client
if @client.nil?
@client = TinyTds::Client.new username: 'user', password: 'pass', host: '192.168.4.4'
@client.execute('use database').do
def @client.execute(sql)
puts sql
super(sql).each(:symbolize_keys => true)
end
end
@client
end