home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DBSQL.ZIP / TABLELST.C < prev    next >
C/C++ Source or Header  |  1990-12-01  |  2KB  |  70 lines

  1. // List of Tables in a database
  2. // Dec 1, 1990
  3.  
  4. #include <os2.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <dbsql.h>
  8.  
  9. PSQLPROCESS pSqlProcess;
  10. CHAR        szDatabaseName[21];
  11.  
  12. VOID main ( VOID );
  13. VOID ListTables ( PSQLPROCESS pSqlProcess );
  14.  
  15. VOID main ( VOID )
  16. {
  17.     printf ( "Enter Database Name: " );
  18.     scanf  ( "%s", szDatabaseName );
  19.  
  20.     printf ( "\n\n" );
  21.     printf ( "Program Started \n" );
  22.     pSqlProcess = SqlOpenDB ( szDatabaseName );
  23.  
  24.     ListTables ( pSqlProcess );
  25. }
  26.  
  27. VOID ListTables ( PSQLPROCESS pSqlProcess )
  28. {
  29.     SHORT   sRow;
  30.     CHAR    szName[19];
  31.     CHAR    szCreator[9];
  32.     CHAR    szType[2];
  33.     SHORT   sColCount;
  34.     LONG    lNumRows;
  35.     CHAR    szComment[255];
  36.  
  37.     printf ( "Opening Database: %s \n\n", szDatabaseName );
  38.  
  39.     SqlCommand ( pSqlProcess, "SELECT Name, Creator, Type, ColCount, Card, Remarks " );
  40.     SqlCommand ( pSqlProcess, "FROM SYSIBM.SYSTABLES " );
  41.  
  42.     if ( SqlExecute ( pSqlProcess ) )
  43.     {
  44.     SqlBindByNum ( pSqlProcess, 1, szName,        BIND_CHAR );
  45.     SqlBindByNum ( pSqlProcess, 2, szCreator,   BIND_CHAR );
  46.     SqlBindByNum ( pSqlProcess, 3, szType,        BIND_CHAR );
  47.     SqlBindByNum ( pSqlProcess, 4, &sColCount,  BIND_CHAR );
  48.     SqlBindByNum ( pSqlProcess, 5, &lNumRows,   BIND_CHAR );
  49.     SqlBindByNum ( pSqlProcess, 6, szComment,   BIND_CHAR );
  50.  
  51.     printf ( "Binded\n\n" );
  52.  
  53.     SqlOpenCursor  ( pSqlProcess );
  54.  
  55.     printf ( "Cursor Open\n\n" );
  56.  
  57.     sRow = 0;
  58.  
  59.     while ( SqlFetchRow ( pSqlProcess ) )
  60.     {
  61.         sRow++;
  62.         printf ( "%3d.  %-18s  %-8s  %1s  %d  %ld  %s\n",
  63.                  sRow, szName, szCreator, szType,
  64.                  sColCount, lNumRows, szComment );
  65.     }
  66.  
  67.     SqlCloseCursor ( pSqlProcess );
  68.     }
  69. }
  70.