home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Demo / PCDUO / data1.cab / Script_Samples / ODBCDEMO.SCP < prev    next >
Encoding:
Text File  |  2003-11-28  |  2.9 KB  |  96 lines

  1. // ODBCDEMO.SCP - Sample Script function to demonstrate ODBC database access.
  2. // Copyright (c) 2000, Vector Networks Limited
  3. // All Rights Reserved
  4. //
  5. // Revision History:
  6. // 6.0 03-Nov-00 DB  - Created.
  7.  
  8. // Predefined variables:
  9. // DataSourceName = "" name of ODBC data source to list Tables
  10. // TableName = "" name of Table to list Columns
  11.  
  12. Function Main ()
  13. Dim DataSourceName as String, TableName as String
  14. Dim DriverList as List, SourceList as List
  15. Dim ColumnList as List, TableList as List 
  16. Dim ColumnNo, DriverNo, SourceNo, TableNo
  17.  
  18.     // Initialise loop count variables
  19.  
  20.     ColumnNo = 0
  21.     DriverNo = 0
  22.     SourceNo = 0
  23.     TableNo = 0
  24.  
  25.     //  If no DSN has been specified, list all of 
  26.     //  the drivers and data sources available
  27.  
  28.     If DataSourceName = "" Then
  29.         Status = dbDrivers (DriverList)
  30.  
  31.         If Status > 0 Then
  32.             Print Status, " Drivers found:"
  33.  
  34.             For Each Driver in DriverList
  35.                 DriverNo = DriverNo + 1
  36.                 Print "Driver ", DriverNo, " = ", Driver
  37.             Next
  38.  
  39.             Print DriverNo, " Drivers listed"
  40.         Endif
  41.  
  42.         Status = dbDataSources (SourceList)
  43.  
  44.         If Status > 0 Then
  45.             Print Status, " Data Sources found:"
  46.  
  47.             For Each Source in SourceList
  48.                 SourceNo = SourceNo + 1
  49.                 Print "Source ", SourceNo, " = ", Source
  50.             Next
  51.  
  52.             Print SourceNo, " Data Sources listed"
  53.         Endif
  54.     Else
  55.         Print "Opening Data Source ", DataSourceName
  56.         Status = dbOpen (DataSourceName)
  57.         Print "Database open status = ", status
  58.  
  59.         // If no TableName was specified, list them all
  60.  
  61.         If Status Then
  62.             If TableName = "" Then
  63.                 Status = dbTables (TableList)
  64.                 Print Status, " Tables found:"
  65.  
  66.                 For Each Table in TableList
  67.                     TableNo = TableNo + 1
  68.                     Print "Table ", TableNo, " = ", Table
  69.                 Next
  70.  
  71.                 Print TableNo, " tables listed from data source ", DataSourceName
  72.             Else
  73.                 Status = dbColumns (TableName, ColumnList)
  74.                 If Status > 0 Then
  75.                     Print "Columns found in Table ", TableName, ":"
  76.  
  77.                     For Each Column in ColumnList
  78.                         ColumnNo = ColumnNo + 1
  79.                         Print "Column ", ColumnNo, " = ", Column
  80.                     Next
  81.  
  82.                     Print ColumnNo, " Columns listed from Table ", TableName
  83.                 Else
  84.                     Print "Table ", TableName, " not found in data source ", DataSourceName
  85.                 Endif
  86.             Endif
  87.  
  88.             // Don't forget to close the data source
  89.  
  90.             dbClose ()
  91.         Else
  92.             Print "Data Source ", DataSourceName, " could not be opened"
  93.         Endif
  94.     Endif
  95. End Function
  96.