Class: XMLService::I_DB2

Inherits:
I_CALL show all
Defined in:
lib/xmlservice.rb

Overview


xmlservice call DB2


Instance Attribute Summary

Attributes inherited from I_CALL

#input, #reponse, #return

Instance Method Summary collapse

Methods inherited from I_CALL

#call, #call_recursive, #dump, #dump_all, #dump_error, #dump_inspect, #dump_inspect_input, #dump_inspect_response, #dump_inspect_returndata, #execute, #format_inspect, #format_inspect_include, #format_inspect_recursive, #out_xml, #reserved_words, #response, #returndata, #xmlservice, #xmlservice_diag_parse, #xmlservice_error

Methods inherited from I_Meta

#add_user_accessor, #instance_variable_forward_get, #instance_variable_forward_set, #remove_user_accessor, #shortCut

Constructor Details

#initialize(query, parms = nil, options = nil) ⇒ I_DB2

Returns a new instance of I_DB2.



2390
2391
2392
2393
2394
# File 'lib/xmlservice.rb', line 2390

def initialize(query,parms=nil,options=nil)
  @xml_query = query
  @xml_parms = parms
  super(options)
end

Instance Method Details

#parse_diag_attrObject



2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
# File 'lib/xmlservice.rb', line 2420

def parse_diag_attr()
  rc = self.xmlservice_diag_parse("/myscript/sql/fetch")
  if rc
    rc = self.xmlservice_diag_parse("/myscript/sql/execute")
  end
  if rc
    rc = self.xmlservice_diag_parse("/myscript/sql/prepare")
  end
  rc
end

#parse_output_attrObject



2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
# File 'lib/xmlservice.rb', line 2395

def parse_output_attr()
  super()
  row = Array.new
  isrow = false
  @xml_doc.elements.each("/myscript/sql/fetch/row") do |element|
    isrow = true
    col = Hash.new
    element.each do |child|
      col[child.attributes['desc']] = child.text
    end
    row[row.count] = col
  end
  if isrow
    @response.add_user_accessor("output", row)
  else
    text = "*NONE"
    @response.add_user_accessor("output", text)
  end
end

#parse_return_attrObject



2414
2415
2416
2417
2418
2419
# File 'lib/xmlservice.rb', line 2414

def parse_return_attr()
  super()
  @xml_doc.elements.each("/myscript/sql/execute/parm") do |element|
    @returndata.add_user_accessor(element.attributes['var'],element.text)
  end
end

#to_xmlObject



2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
# File 'lib/xmlservice.rb', line 2430

def to_xml
  rows = ""
  error = " error='fast'"
  if @xml_options
    if @xml_options.has_key?(:error)
      error = " error='#{@xml_options[:error]}'"
    end
  end
  xml = "<sql>\n"
  xml << "<prepare #{error}>"
  xml << @xml_query.to_s
  xml << "</prepare>\n"
  if @xml_parms
    xml << "<execute #{error}>\n"
    if @xml_parms.is_a?(XMLService::I_Base)
      parms = @xml_parms.value
    else
      parms = @xml_parms
    end
    if parms.is_a?(Array)
      i = 0
      parms.each do |v|
        n = " var='parm#{i.to_s}'"
        xml << "<parm io='both' #{n}>#{v}</parm>\n"
        i += 1
      end
    elsif parms.is_a?(Hash)
      parms.each do |a,v|
        n = " var='#{a}'"
        xml << "<parm io='both' #{n}>#{v}</parm>\n"
      end
    else
      n = " var='parm0'"
      v = parms
      xml << "<parm io='both' #{n}>#{v}</parm>\n"
    end
    xml << "</execute>\n"
  else
    xml << "<execute #{error}/>\n"
  end
  xml << "<fetch block='all' desc='on' #{error}/>\n"
  xml << "</sql>\n"
  xml
end