" *****************************************************************************************************
*
*   specols.txt
*
*   This examples shows how to use specialColumns
*
*
******************************************************************************************************"

|connection1  aTextDisplay connectString statement1 icol
 fColType tableQualifier tableOwner tableName fScope fNullable|

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




fColType := 
  Prompter prompt: 'Please Enter column type - BEST ROWID , ROWVER (1,2):' default: ''.   
tableQualifier:= Prompter prompt: 'Please Enter a table qualifier:' default: ''.
tableOwner:= Prompter prompt: 'Please Enter a table owner:' default: ''.
tableName := Prompter prompt: 'Please Enter a table name:' default: ''.
fScope:=
  Prompter prompt: 'Enter scope - Current Row, Transaction, Session (0,1,2):' default: ''.
fNullable := Prompter prompt:
 'Enter if columns can be null - NO NULLS, NULLABLE (0,1):' default: ''.


"*** get the columns  ***"
statement1 specialColumns: fColType asInteger
                    tableQualifier: tableQualifier
                    tableOwnerQualifier: tableOwner
                    tableNameQualifier: tableName
                    fScope: fScope asInteger
                    fNullable: fNullable asInteger.

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