home *** CD-ROM | disk | FTP | other *** search
- // ODBCDEMO.SCP - Sample Script function to demonstrate ODBC database access.
- // Copyright (c) 2000, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 6.0 03-Nov-00 DB - Created.
-
- // Predefined variables:
- // DataSourceName = "" name of ODBC data source to list Tables
- // TableName = "" name of Table to list Columns
-
- Function Main ()
- Dim DataSourceName as String, TableName as String
- Dim DriverList as List, SourceList as List
- Dim ColumnList as List, TableList as List
- Dim ColumnNo, DriverNo, SourceNo, TableNo
-
- // Initialise loop count variables
-
- ColumnNo = 0
- DriverNo = 0
- SourceNo = 0
- TableNo = 0
-
- // If no DSN has been specified, list all of
- // the drivers and data sources available
-
- If DataSourceName = "" Then
- Status = dbDrivers (DriverList)
-
- If Status > 0 Then
- Print Status, " Drivers found:"
-
- For Each Driver in DriverList
- DriverNo = DriverNo + 1
- Print "Driver ", DriverNo, " = ", Driver
- Next
-
- Print DriverNo, " Drivers listed"
- Endif
-
- Status = dbDataSources (SourceList)
-
- If Status > 0 Then
- Print Status, " Data Sources found:"
-
- For Each Source in SourceList
- SourceNo = SourceNo + 1
- Print "Source ", SourceNo, " = ", Source
- Next
-
- Print SourceNo, " Data Sources listed"
- Endif
- Else
- Print "Opening Data Source ", DataSourceName
- Status = dbOpen (DataSourceName)
- Print "Database open status = ", status
-
- // If no TableName was specified, list them all
-
- If Status Then
- If TableName = "" Then
- Status = dbTables (TableList)
- Print Status, " Tables found:"
-
- For Each Table in TableList
- TableNo = TableNo + 1
- Print "Table ", TableNo, " = ", Table
- Next
-
- Print TableNo, " tables listed from data source ", DataSourceName
- Else
- Status = dbColumns (TableName, ColumnList)
- If Status > 0 Then
- Print "Columns found in Table ", TableName, ":"
-
- For Each Column in ColumnList
- ColumnNo = ColumnNo + 1
- Print "Column ", ColumnNo, " = ", Column
- Next
-
- Print ColumnNo, " Columns listed from Table ", TableName
- Else
- Print "Table ", TableName, " not found in data source ", DataSourceName
- Endif
- Endif
-
- // Don't forget to close the data source
-
- dbClose ()
- Else
- Print "Data Source ", DataSourceName, " could not be opened"
- Endif
- Endif
- End Function
-