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

  1. /* Test of DbSql.DLL */
  2.  
  3.  
  4. #include <os2.h>
  5. #include <stdio.h>
  6. #include "dbsql.h"
  7.  
  8. PSQLPROCESS pSqlProcess;
  9.  
  10. void DoQuery ( PSQLPROCESS pSqlProcess );
  11.  
  12. main ( )
  13. {
  14.     pSqlProcess = SqlOpenDB ( "Sample", "MASTER", "ACCESS" );
  15.  
  16.     printf ( "\n\nStart Query\n\n" ); 
  17.     DoQuery ( pSqlProcess );
  18.     
  19.     SqlCloseDB ( pSqlProcess );
  20.  
  21.     return 0;
  22. }
  23.  
  24.  
  25. void DoQuery ( PSQLPROCESS pSqlProcess )
  26. {
  27.     SQLCOLUMNINFO   SqlCI;
  28.     SHORT   nc;
  29.     SHORT   i;
  30.     SHORT   sRow;
  31.     CHAR    szName[16];
  32.     CHAR    szJob[11];
  33.     CHAR    szDeptName[16];
  34.     CHAR    szDivision[16];
  35.     CHAR    szLocation[21];
  36.     double  salary;
  37.     
  38.     SqlCommand ( pSqlProcess, "SELECT Name, Job, DeptName, Division, Location, Salary * 1.5 " );
  39.     SqlCommand ( pSqlProcess, "FROM   Staff, Org " );
  40.     SqlCommand ( pSqlProcess, "WHERE Manager = ID " );
  41.     
  42.     if ( SqlExecute ( pSqlProcess ) )
  43.     {
  44.         nc = SqlGetNumberColumns ( pSqlProcess );
  45.         printf ( "Number of columns: %d\n", nc );
  46.         for ( i = 0; i < nc; i++ )
  47.         {
  48.             SqlCI = SqlGetColumnNameInfo ( pSqlProcess, i );
  49.             printf ( "Column: %-30s  Type: %d   Length: %d\n", SqlCI.szColumnName, SqlCI.sSqlType, SqlCI.sSqlLength );
  50.         }
  51.         printf ( "\n\n" );
  52.  
  53.         SqlBindByNum ( pSqlProcess, 1, szName,     BIND_CHAR );
  54.         SqlBindByNum ( pSqlProcess, 2, szJob,      BIND_CHAR );
  55.         SqlBindByNum ( pSqlProcess, 3, szDeptName, BIND_CHAR );
  56.         SqlBindByNum ( pSqlProcess, 4, szDivision, BIND_CHAR );
  57.         SqlBindByNum ( pSqlProcess, 5, szLocation, BIND_CHAR );
  58.         SqlBindByNum ( pSqlProcess, 6, &salary,    BIND_DECIMAL );
  59.  
  60.     SqlOpenCursor  ( pSqlProcess );
  61.  
  62.     sRow = 0;
  63.  
  64.     while ( SqlFetchRow ( pSqlProcess ) )
  65.     {
  66.         sRow++;
  67.             printf ( "%3d. %-10s  %-5s  %-15s  %-10s  %-13s  %7.2lf\n", sRow, szName, szJob, szDeptName, szDivision, szLocation, salary );
  68.     }
  69.  
  70.     SqlCloseCursor ( pSqlProcess );
  71.     }
  72. }
  73.