home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DBSQL.ZIP / COLUMLST.C next >
C/C++ Source or Header  |  1990-12-01  |  2KB  |  75 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. CHAR        szTableName[21];
  12.  
  13. VOID main ( VOID );
  14. VOID ListTables ( PSQLPROCESS pSqlProcess );
  15.  
  16. VOID main ( VOID )
  17. {
  18.     printf ( "Enter Database Name: " );
  19.     scanf  ( "%s", szDatabaseName );
  20.     printf ("\n" );
  21.     printf ( "Enter Table Name: " );
  22.     scanf  ( "%s", szTableName );
  23.  
  24.     printf ( "\n\n" );
  25.     printf ( "Program Started \n" );
  26.     pSqlProcess = SqlOpenDB ( szDatabaseName );
  27.  
  28.     ListTables ( pSqlProcess );
  29. }
  30.  
  31. VOID ListTables ( PSQLPROCESS pSqlProcess )
  32. {
  33.     SHORT   sRow;
  34.     CHAR    szName[19];
  35.     CHAR    szType[9];
  36.     SHORT   sLength;
  37.     SHORT   sScale;
  38.     CHAR    szNulls[2];
  39.     CHAR    szComment[255];
  40.  
  41.     printf ( "Opening Database: %s \n\n", szDatabaseName );
  42.  
  43.     SqlCommand ( pSqlProcess, "SELECT Name, ColType, Length, Scale, Nulls, Remarks " );
  44.     SqlCommand ( pSqlProcess, "FROM SYSIBM.SYSCOLUMNS " );
  45.     SqlCommandf ( pSqlProcess, "WHERE TbName = '%s' ", szTableName );
  46.  
  47.     if ( SqlExecute ( pSqlProcess ) )
  48.     {
  49.     SqlBindByNum ( pSqlProcess, 1, szName,        BIND_CHAR );
  50.     SqlBindByNum ( pSqlProcess, 2, szType,        BIND_CHAR );
  51.     SqlBindByNum ( pSqlProcess, 3, &sLength,    BIND_SHORT );
  52.     SqlBindByNum ( pSqlProcess, 4, &sScale,     BIND_SHORT );
  53.     SqlBindByNum ( pSqlProcess, 5, szNulls,     BIND_CHAR );
  54.     SqlBindByNum ( pSqlProcess, 6, szComment,   BIND_CHAR );
  55.  
  56.     printf ( "Binded\n\n" );
  57.  
  58.     SqlOpenCursor  ( pSqlProcess );
  59.  
  60.     printf ( "Cursor Open\n\n" );
  61.  
  62.     sRow = 0;
  63.  
  64.     while ( SqlFetchRow ( pSqlProcess ) )
  65.     {
  66.         sRow++;
  67.         printf ( "%3d.  %-18s  %-8s  %d  %d  %1s  %s\n",
  68.                  sRow, szName, szType, sLength,
  69.                  sScale, szNulls, szComment );
  70.     }
  71.  
  72.     SqlCloseCursor ( pSqlProcess );
  73.     }
  74. }
  75.