1 Reply Latest reply on Nov 5, 2013 5:26 PM by Daniel Silva

    Help with ruby source adapter issue

    Daniel Silva

      Trying to create a query function using the DBI gem to query the customer's back end through ODBC just for a proof of concept.  We have had some challenges with unprintable characters in the data and things like that, be we are now at the point where we seem to have the query working.  If I run it from a .rb file or even within my rhoconnect source adapter, I get what looks like good data.  If I put a line at the end of the query that says puts @result, I get what looks like a good result set, but it never syncs to the mobile app running on rhosimulator.  If I take the result set and just plug it directly into the source adapter, it works fine (using the same data).  Not sure where to go from here.  Looking for any pointers to help me figure out what's going on. I am not a ruby guru, so I may very well be missing something basic.

       

      This works.

        def query(params=nil)

          @result={

          "1"=> {

          "OCCMP" =>"U1",

          "OCREF" => "0",

          "OCISEQ" => "0.0",

          "OCSEQ" => "1.0",

          "OCASEQ" => "0.0",

          "OCCMNT" => "TEST DATA",

          "OCTYPE" => "R"

          },

          "2"=> {

          "OCCMP" =>"U1",

          "OCREF" => "1",

          "OCISEQ" => "0.0",

          "OCSEQ" => "1.0",

          "OCASEQ" => "0.0",

          "OCCMNT" => "TEST DATA",

          "OCTYPE" => "K"

          }}

        end

       

      This is the code that produced that result set, yet it does not work if I try to use it directly.

      def query(params=nil)

          puts "query start"

          @result={}

          dbconn = DBI.connect('DBI:ODBC:DEVRM','LAWSONTEST', 'LAWSONTEST')

        

       

      sqlst5 = dbconn.prepare("select * from wsdata.ORDCOMFL fetch first 2 rows only")

      sqlst5.execute

      @cnt = 1

      @row = sqlst5.fetch

       

      puts "query fetch"

      @results="{\n"

      while  @row

      puts "looping results"

      @results=@results+"\""+@cnt.to_s+"\"=> {\n"+"\"OCCMP\" =>\""+@row.by_field("OCCMP").to_s+"\",\n" +"\"OCREF\" => \""+@row.by_field("OCREF#").to_int.to_s+"\",\n" +"\"OCISEQ\" => \""+@row.by_field("OCISEQ").to_f.to_s+"\",\n"+"\"OCSEQ\" => \""+@row.by_field("OCSEQ#").to_f.to_s+"\",\n"+"\"OCASEQ\" => \""+@row.by_field("OCASEQ").to_f.to_s+"\",\n"+"\"OCCMNT\" => \""+"TEST DATA" + "\",\n"+"\"OCTYPE\" => \""+@row.by_field("OCTYPE")+"\"\n},\n"

      @row = sqlst5.fetch

      @cnt = 1+@cnt

      end

      @results = @results.chop.chop

      @result=@results+"}"

       

      #puts "end"

      #puts @result

      #@result 

       

      end