" *****************************************************************************************************
*
*  descparm.txt
*
*   This examples shows how to use describe Param  
*
*
******************************************************************************************************"

|connection1  aTextDisplay connectString statement1 ipar aSqlStatement |

aTextDisplay := TextWindow  windowLabeled: 'ODBC Interface - Using describeParam '
                           frame: (0 @ 0 corner: 1000 @ 1000).
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
    ].



" **** tableQualifier, tableOwner and tablename cannot accept search patterns !!!! ***"

aSqlStatement:= Prompter prompt: 'Please Enter a SQL Statement with Parameter markers (?):' default: ''.

" *** Prepare the Statement ***"
statement1 prepare: aSqlStatement.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].



 
"*** display the characteristics of the parameters ***"
1 to: (statement1 describeParams) do:
    [ :icol |
        aTextDisplay nextPutAll: 'Parameter: ', icol asString ; cr
                             ;nextPutAll:  (OdbcSqlTypes keyAtValue: (statement1 paramSqlType: icol)) ; tab
                             ; nextPutAll: (statement1 paramLength: icol) asString ; tab
                             ; nextPutAll: (statement1 paramibScale: icol) asString ; tab
                             ; nextPutAll: (statement1 paramfNullable: icol) asString
                             ; cr ; cr.
      ].   

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



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 nextPutAll: '*** finished executing ***'.
