Hello,

I need a simple routine, that read a SQL statement from a file and display
the result in a list view window.

In the past I already wrote routines, that use bsf4rexx to read data from
DB2 tables, so I only want to add

the list view part.

 

First problem: to move the data, that I read into a stem named rec. with the
structur rec.row.column, to the

object oriented program part. I found
http://comments.gmane.org/gmane.comp.lang.rexx.oorexx.user/1625

and it works.

 

Second problem: because the number of columns to be display should be
variable I must use addRowFromArray -

but I haven't found a way to make it work as expected. 

 

Based on the example from the OO-Dialog Guide chapter 4.11

                sql = 'SELECT * FROM foods ORDER BY name;'

                data = dbConn~exec(sql, .true)

                dbConn~close

                self~insertListViewColumns(list, data[1])

                do i = 2 to data~items

                               list~addRowFromArray(data[i], , 'null')

                end

 

I tested  

  do j = 1 to self~r

     do i = 1 to self~cc

        lv~addRowFromArray( data.[j,i], , 'null')

     end

  end

 

and

 

  data.[0] = self~r

  do j = 1 to self~r

                 data.[j,0] = self~cc

                 do i = 1 to self~cc

        data.[j,i] = self~rec.[j,i]

     end

  end

 

  do j = 1 to self~r

     lv~addRowFromArray( data.[j], , 'null')

  end

 

but the result is always the same: only the first column is populated with
data.

 

Without the dot after data I got the message

 

    90 *-* say "jexc~toString:" jexc~toString   -- let the Java object
create a string value

Error 97 running D:\Rexx\ViewMessages\ViewMessages.rex line 90:  Object
method not found

Error 97.1:  Object "[]" does not understand message "TOSTRING"

 

I know my general problem is that I'm not familiar enough with the object
oriented part of oorexx and with windows dialog programming but maybe
somebody give me some hints to solve my problem.

 

regards

Roger

 

 

 

prop      = .bsf~bsf.importClass("java.util.Properties")

diag      = .bsf~bsf.importClass("com.ibm.db2.jcc.DB2Diagnosable")

ca                           =
.bsf~bsf.importClass("com.ibm.db2.jcc.DB2Sqlca")

driverMgr = .bsf~bsf.loadClass("java.sql.DriverManager")

 

-- instantiate jdbc driver 

bsf.loadClass('com.ibm.db2.jcc.DB2Driver')~newinstance

 

signal on syntax

-- make the dbms connection and create a statement

con = driverMgr~GetConnection(jdbcconn,user,password)

statement = con~createStatement

 

-- select database content: specify query and execute to get result set

rs = statement~executeQuery(stmt)

 

rsmtadta = rs~getMetaData()

cc = rsmtadta~getColumnCount()

 

do i = 1 to cc

                               col.Name.i = rsmtadta~getColumnName(i)

                 col.Type.i = rsmtadta~getColumnTypeName(i)

                 col.Len.i  = 10

end

 

r = 0

do while rs~next              -- iterate over rows in result set

                r = r + 1

                do i = 1 to cc

     rec.r.i = rs~getString(col.Name.i)

     if rec.r.i = "The NIL object" then rec.r.i = 'null'

     l = Length(strip(rec.r.i))

     If col.Len.i < l then col.Len.i = l

  end

end

say

rs~close()

 

.application~useGlobalConstDir("O", "resource.h")

 

dlg = .VM~new("ViewMessages.rc", IDD_DIALOG_VM)

if dlg~initCode <> 0 then do

  return 99

end

dlg~setArgs(rec.,col.,cc,r)

 

dlg~execute("SHOWTOP")

 

return 0

 

syntax:

trace o

-- fragment that should reside in your syntax condition handling code

 

   jexc=condition("Additional")~at(2)   -- second entry in the ooRexx array

   say "jexc~toString:" jexc~toString   -- let the Java object create a
string value

 

   jobj=jexc~getTargetException  -- <== fetch the original exception

   say "jobj~toString:" jobj~toString   -- let the Java object create a
string value

 

   if jobj~bsf.isA('com.ibm.db2.jcc.DB2Diagnosable') then

   do

       -- now you know that that exception has all methods from
DB2Diagnosable!

       sqlca=jobj~getSclca

       say "sqlCode ="sqlca~getSqlCode 

       say "sqlState="sqlca~sqlState   -- note: BSF4ooRexx treats Java "get"
methods as ooRexx getter methods (one can omit the prefix "get" in ooRexx)

       say "sqlMsg  ="sqlca~sqlMessage

       -- ...

   end

 

  return

 

::requires "ooDialog.cls"

 

::requires bsf.cls            -- get the Java support

 

::class 'VM' subclass RcDialog

 

::attribute rec.

::attribute col.

::attribute cc

::attribute r

 

::method init

  use arg rcFile,id,dlgData.,hFile,rec.,col.,cc,r

  

  self~init:super(rcFile, id, hFile)

  

::method setArgs

  use strict arg p1., p2., p3, p4

  self~rec.=p1.

  self~col.=p2.

  self~cc=p3

  self~r=p4

 

::method initDialog

  expose menuBar lv

  menuBar = .ScriptMenuBar~new("ViewMessages.rc", IDR_MENU_VM, , , .true,
self)

 

  lv = self~newListView(IDC_COLUMN_LIST)

  do i = 1 to self~cc

     lv~insertColumnPX(i-1, self~col.[name,i], self~col.[len,i])

  end

 

  data.[0] = self~r

  do j = 1 to self~r

                 data.[j,0] = self~cc

                 do i = 1 to self~cc

        data.[j,i] = self~rec.[j,i]

     end

  end

  trace ?i

  do j = 1 to self~r

     lv~addRowFromArray( data[j], , 'null')

  end

 

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to