;
; ------------------------------------------------------------
;
;   PureBasic - Database example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;

If UseODBCDatabase() = 0
  MessageRequester("Error", "Can't initialize Database (ODBC v3 or better) environment", 0)
  End
EndIf

OpenConsole()

Dim DatabaseType.s(4)
DatabaseType(0) = "Unknown"
DatabaseType(1) = "Numeric"
DatabaseType(2) = "String"
DatabaseType(3) = "Float"

; First, let's see which drivers are attached to the system..
;

If ExamineDatabaseDrivers()
  While NextDatabaseDriver()
    PrintN(DatabaseDriverName()+" - "+DatabaseDriverDescription())
  Wend
EndIf

; Open an ODBC database
;
If OpenDatabaseRequester(0)

  PrintN("Database successfully opened !")
  PrintN("Type EXIT to quit.")
  PrintN("Command example: select * from user;")

  Repeat
    Print("SQL Command: ")
    Command$ = Input()
    PrintN("")

    Select UCase(Command$)
      Case "EXIT"
        Quit = 1

      Default

        If DatabaseQuery(0, Command$)

          NbColumns = DatabaseColumns(0)
          PrintN("NbColums: " + Str(NbColumns))

          For k=0 To NbColumns-1
            PrintN(DatabaseColumnName(0, k) + " - " + DatabaseType(DatabaseColumnType(0, k)))
          Next

          PrintN("")
          Print ("Press return to continue") : Input()
          PrintN("")
          PrintN("Query Result -------------------------------------")

          While NextDatabaseRow(0)
            PrintN(GetDatabaseString(0, 0))
          Wend

          PrintN("--------------------------------------------------")
        Else
          PrintN("Bad Query !")
        EndIf
    EndSelect
  Until Quit = 1
Else
 MessageRequester("Info", "Operation canceled", 0)
EndIf

End>