" *****************************************************************************************************
*
* natSql.txt
*
* This examples shows how to  use nativeSQL
*
******************************************************************************************************"

|connection1  aTextDisplay connectString sqlString|

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



" *** Open the connection ****"

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



" *** Driver  Connect ***
 Valid Driver completions code are in OdbcDriverCompletions "

connectString :=  connection1 driverConnect: '' window: aTextDisplay
        driverCompletion: (OdbcDriverCompletions at: 'DRIVERPROMPT').

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


sqlString := Prompter prompt: 'Please Enter a SQL Statement to be translated:' default: ''.

"*** Translate the string ****"
aTextDisplay cr
                     ; nextPutAll: 'Output from nativeSQL:';cr
                
                    ;nextPutAll: (connection1 nativeSQL: sqlString)  ;cr.

connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 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 ***'.
