(click to open)

Quick Page Table of Contents


Ruby Toolkit Don: Establishing a Connection


XMLService requires a connection. The connection method parameters can contain:

  1. all detailed options
  2. simply reference your existing Rails database.yml configuration for the ibm_db ActiveRecord adapter.

The following ruby code, for example, creates a connection to the current IBMi and then prints the output from the QTIME system value on the shell console:

require 'xmlservice'
  connection: 'ActiveRecord', adapter: 'ibm_db', database: '*LOCAL',
  username: 'USER400', password: 'secret'
wrksysval ="system -i 'WRKSYSVAL SYSVAL(QTIME) OUTPUT(*PRINT)'")
puts wrksysval.out_xml

But, if you are in the context of a Rails application that has an ibm_db adapter already configured in database.yml, the establish connection method need only be passed the connection adapter type of ActiveRecord. The following shows how to run the WRKSYSVAL command from a Rails console:

/YOUR_RAILS_APP> rails console
irb(main):001:0>  require 'xmlservice'
irb(main):001:0>  ActiveXMLService::Base.establish_connection connection: 'ActiveRecord'
irb(main):001:0>  cmd ="system -i 'WRKSYSVAL SYSVAL(QTIME) OUTPUT(*PRINT)'")
irb(main):001:0>  cmd.xmlservice
irb(main):001:0>  puts cmd.out_xml