" *****************************************************************************************************
*
*   proccols.txt
*
*   This examples shows how to use procedureColumns
*
*
******************************************************************************************************"

|connection1  aTextDisplay connectString statement1 icol 
 procQualifier procOwner procName columnName|

aTextDisplay := TextWindow  windowLabeled: 'ODBC Interface - Using procedureColumns'
                           frame: (0 @ 0 corner: 500 @ 500).
aTextDisplay cr.



" *** Open the connection ****"
connection1 := OdbcConnection open.
connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].



" *** Driver  Connect ***  "
connectString :=  connection1 driverConnect: '' window: aTextDisplay
        driverCompletion: (OdbcDriverCompletions at: 'DRIVERPROMPT').

connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].

" *** allocate a new statement *** "
statement1:= connection1 newStatement.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].





procQualifier:= Prompter prompt: 'Please Enter a proc qualifier :' default: ''.
procOwner:= Prompter prompt: 'Please Enter a proc owner or search pattern:' default: ''.
procName := Prompter prompt: 'Please Enter a proc name or search pattern:' default: ''.
columnName := Prompter prompt: 'Please Enter a column name or search pattern:' default: ''.     


"*** get the procedures ***"
statement1 procedureColumns: procQualifier procOwnerQualifier: procOwner
            procNameQualifier: procName columnNameQualifier: columnName.

statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].
icol := statement1 numberOfColumns.
                                                   

"*** the answer is a standard result set !!! ***"
statement1 fetch.
[statement1 hasSuccess]
    whileTrue: [
            aTextDisplay cr.
            1 to: icol do: [ :col |
                aTextDisplay nextPutAll: (statement1 getData: col) ; tab
            ].
            statement1 fetch
    ].

aTextDisplay cr.

"*** free the statement *** "
statement1 free: (OdbcConstants at: 'SQLDROP').
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].

" *** disconnect *** "
connection1 disconnect.
connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].


" *** free the connection *** "

connection1 free.
connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].


aTextDisplay cr ; nextPutAll: '*** finished executing ***'.
