Who Am I LSX Sample Script

Mindwatering Incorporated

Author: Tripp Black

Created: 09/23/2010 at 01:31 PM

 

Category:
Notes Developer Tips
LSX (LotusScript Extensions/Connectors)

%REM
Agent LC-SampleData
Created Jan 1, 2006 by Tripp Black
Description: Used to get Field Schema and 1st record/row's data
%END REM
Option Public
UseLSX "*lsxlc"
Option Declare

Sub Initialize()
Dim lcSrc As New LCConnection ("odbc2")
Dim lcFldLst As New LCFieldlist
Dim lcFld As LCfield
Dim pos As Long
Dim dtype As Long
Dim flags As Long
Dim sqlqry As String ' sql query
Dim fieldname As String
Dim fldnmLst() As String ' list of fieldnames to cycle back around
Dim fldnmlstcount As Long ' counter for list

On Error GoTo ErrorHandler

REM setup connection
lcSrc.Server = "ODBCRedigisteredDatabaseObject"
lcSrc.Userid = "myid"
lcSrc.Password = "mypassw0rd"
lcSrc.Connect
sqlqry = "select * from mytable"
REM now perform the catalog action - in this case for fields
If (lcSrc.Execute (sqlqry, lcFldLst) = 0) Then
Print "The query results not found."
Else
Print "The query results fieldlist is:"
fldnmlstcount = 0
ReDim fldnmLst(fldnmlstcount)
pos = LCLIST_FIRST
While (lcFldLst.List (pos, , , dtype, flags, fieldname) = True)
Print " " + fieldname + " is type #" +_
CStr(dtype) + " with flags " + Hex(flags)
pos = LCLIST_NEXT
' add field name to list
ReDim Preserve fldnmLst(fldnmlstcount)
fldnmLst(fldnmlstcount) = fieldname
fldnmlstcount = fldnmlstcount + 1
Wend
Print "[ done field list ] <br><br>"
' cycle back to first record - loop through record's fields and output values
pos = LCLIST_FIRST
While (lcSrc.Fetch (lcFldLst) > 0)
Print "Record Fields... <br>"
For fldnmlstcount = 0 To UBound(fldnmLst)
Set lcFld = lcFldLst.Lookup(fldnmLst(fldnmlstcount) )
Print "Field: " & fldnmLst(fldnmlstcount) & " = " & lcFld.text(0) & " <br>"
Next fldnmlstcount
Print "... end first record <br>"
GoTo SExit
Wend
End If

SExit:
' kill and exit
Set lcFldLst = Nothing
Set lcsrc = Nothing
Exit Sub

ErrorHandler:
Print "Unexpected error: (" & CStr(Err) & ") " & Error$ & ", on line: " & CStr(Erl) & "."
Exit sub
End Sub


previous page