" *****************************************************************************************************
*
*  getdata2.txt
*
*   This examples shows how to use getData to retrieve a column value
*   Which exceeds the receiving area.
*
*
*
******************************************************************************************************"

|connection1  aTextDisplay connectString statement1 sqlStatement|

aTextDisplay := TextWindow  windowLabeled: 'ODBC Interface - Using getData'
                           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:= Prompter prompt: 'Please Enter a select SQL statement:' default: ''.


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


"*** Set the defaultSize to receive data to something ridiscously small
       ( normally default is 512)
****"
statement1 defaultSize: 6.

" *** display the receiving area size ***"
aTextDisplay nextPutAll: ' The size of the receiving area is: '
                                   ; nextPutAll: statement1 defaultSize asString
                                   ; cr.

"*** fetch the rows and display the values ***"

statement1 fetch.
   [statement1 hasSuccess]
        whileTrue: [
            1 to: statement1 numberOfColumns do:
                [ :icol |
                        " *** get the column value *** "
                        aTextDisplay nextPutAll: (statement1 getData: icol).

                        "*** There is some more data to get   ***"
                        [statement1 hasSuccessWithInfo]
                            whileTrue: [
                                 aTextDisplay nextPutAll: (statement1 getData: icol).
                            ].
                            aTextDisplay tab.
                ].
             aTextDisplay cr.
             statement1 fetch.
      ].

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