DB2 with LotusNotes

Hi All, I am trying to retreive data from DB2 to a Lotus Notes Application with Lotus Script, so I am using this code to do it: odbcResultSet.GetValue( item ), item is a String that contains the colummn name. So far, it works well with strings, but now I must retrieve other datatypes such: Integer, Date, Double, Character and VarChar, this datatypes were defined when database was created. By the way, I cann’t do any change on this. The data received is corrupt not an error but data corrupted. Please if someone knows how to retrievi it, let me know as soon as possible. Thank’s in advanced.

Itamar Moreira.

Subject: DB2 with LotusNotes

First of all, you should read the Lotus Connectors section of the Designer Help file. It goes through everything I explain here. It is difficult to wrap your mind around the objects at first, but experimenting a bit yields good results.

The method I propose here is not the ODBC method you’re currently using. I did it this way because it’s much more efficient than ODBC and requires less setup. This is mentionned several times in the help files.

Dim nd As NotesDocument

Dim src As LCConnection

Set src = New LCConnection(“db2”)

src.Database = “XXXXXXXX”

src.UserID = “XXXXXX”

src.Password = “XXXXXXX”

src.Connect

Dim fl As New LCFieldList 'This is a logical representation of a record output

Dim key_fl As New LCFieldList(1,0) 'This object represents a key to give parameters to the select statement.

Dim keyfld As New LCField(LCTYPE_TEXT,1)

'You might not need these last 2 if you want to retrieve all the records in your DB2 table

'The LCField is the object where the data’s reference will be held

Dim myfld1 As New LCField (LCTYPE_TEXT, 1)

'If you want to retrieve Packed, Zoned, Numeric DB2 fields, use LCTYPE_NUMERIC

'If you want to use a key to retrieve only certain records

Set keyfld = key_fl.Append (“DB2_Fieldname”, LCTYPE_TEXT)

keyfld.Flags = LCFIELDF_KEY

keyfld.value = “Code900”

'This will get all records whose DB2_Fieldname field is equal to “Code900”

You can have multiple attributes to keyfld to do greater than, less than etc. The documentation explains the different key attributes.

'Then set a temporary variable to execute the search for those records

count=p_src.Select (Nothing, 1,fl)

'The fl Fieldlist object now points to the first row in the DB2 table.

Using a key to get rows, your instruction would look like

count=p_src.Select (key_fl, 1,fl)

'You don,t have to do the following, but it’s more efficient if you’re looping through many records

Set myfld1 = fl.Lookup (“DB2_Fieldname”)

'Now you have to actually fetch the data pointed to by fl

count = p_src.Fetch (fl, 1, 1)

'This retrieves the current row.If you execute this instruction many times in a row, it fetches the data for the next row each time.

'But looping through without doing anything with the data is kind of pointless, so before fetching again, do something with the data

Set nd= New NotesDocument

nd.form = “myform”

nd.mynotesfield = myfld1.text(0)

Call nd.Save(True,False)

I think from this you get a good idea how to go on by looping through successive fetches. I hope I didn’t just confuse you. Good luck,

Luc Millette

Subject: RE: DB2 with LotusNotes

Sorry about my ignorance, but I can not do it. Could you please post a peice of code? Such explain how I can retrive a row with some colummns and to do datatype recognization should be automatic, because I am building a code like an API and this must be generic, because most part of time I won’t know the datatype field. I have been doing what you wrote previously. Could you do that please, thank’s in advance.

Itamar Moreira

Subject: DB2 with LotusNotes

You can try to convert data to a data type which is readable by lotusscript. Easiest to do it is by using CAST method.SELECT CAST(C.Surname as text) as LastName, CAST(C.Firstname as text) as FirstName, CAST(CAST(C.Firstname as varchar)+’ '+CAST(C.Surname as varchar) as text) as FullName WHERE …

You can do similar CAST operations with other data types. Take also a look at LC classes, maybe they can give your better possibilities of automatic type conversion.