" *****************************************************************************************************
*
*  bindparm.txt
*
*   This examples shows how to use bindInputParameter
*   The example is restricted to char type parameters.
*
*
******************************************************************************************************"

|connection1  aTextDisplay connectString statement1 sqlStatement parmValue|

aTextDisplay := TextWindow  windowLabeled: 'ODBC Interface - Using bindInputParameter'
                           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
    ].

sqlStatement:='insert into testchar values(?)'.

"*** prepare   ***"
statement1 prepare: sqlStatement.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].

"*** change the Scroll Options ***"
statement1 paramOptions: 2.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].

statement1 bindInputParameter: 1 fSqlType: String fSqlType  maxSize: 5.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].

parmValue := #('aa' 'bbbb').
statement1 setParameter: 1 value: parmValue.

"*** execute the statement  ***"
statement1 execute.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].



"*** free the statement *** "
statement1 drop.
statement1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: statement1 getMessage; cr
    ].

" commit the statement - Watcom SQL does not autocommit ..."
connection1 commit.


" *** 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 ***'.
