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

  1. /* Test of DbSql.DLL */
  2.  
  3.  
  4. #include <os2.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "dbsql.h"
  8.  
  9. PSQLPROCESS pSqlProcess;
  10.  
  11. void DoQuery ( PSQLPROCESS pSqlProcess );
  12.  
  13. main ( )
  14. {
  15.     pSqlProcess = SqlOpenDB ( "Desktop", "MASTER", "ACCESS" );
  16.  
  17.     printf ( "Importing Data \n\n" );
  18.     if ( !SqlImport ( pSqlProcess, "Bradley.Test", "A:\Address.WKS", 2, 1  ) )
  19.     {
  20.     printf ( "Error Importing File\n\n" );
  21.     SqlCloseDB ( pSqlProcess );
  22.     exit(1);
  23.     }
  24.  
  25.     printf ( "\n\nStart Query\n\n" ); 
  26.     DoQuery ( pSqlProcess );
  27.  
  28.     if ( !SqlExport ( pSqlProcess, "Bradley.Address", "A:\Address.TXT", 1 ) )
  29.     printf ( "Error Exporting File\n\n" );
  30.  
  31.  
  32.     SqlCloseDB ( pSqlProcess );
  33.  
  34.     return 0;
  35. }
  36.  
  37.  
  38. void DoQuery ( PSQLPROCESS pSqlProcess )
  39. {
  40.     SQLCOLUMNINFO   SqlCI;
  41.     SHORT   nc;
  42.     SHORT   i;
  43.     SHORT   sRow;
  44.     CHAR    szFirstName[26];
  45.     CHAR    szLastName[26];
  46.     CHAR    szHomePhone[16];
  47.     CHAR    szCity[26];
  48.     CHAR    szState[5];
  49.  
  50.     SqlCommand ( pSqlProcess, "SELECT FirstName, LastName, HomePhone, City, State " );
  51.     SqlCommand ( pSqlProcess, "FROM Test " );
  52.     SqlCommand ( pSqlProcess, "WHERE HomePhone IS NOT NULL " );
  53.     SqlCommand ( pSqlProcess, "ORDER BY LastName " );
  54.  
  55.     if ( SqlExecute ( pSqlProcess ) )
  56.     {
  57.         nc = SqlGetNumberColumns ( pSqlProcess );
  58.         printf ( "Number of columns: %d\n", nc );
  59.         for ( i = 0; i < nc; i++ )
  60.         {
  61.             SqlCI = SqlGetColumnNameInfo ( pSqlProcess, i );
  62.             printf ( "Column: %-30s  Type: %d   Length: %d\n", SqlCI.szColumnName, SqlCI.sSqlType, SqlCI.sSqlLength );
  63.         }
  64.         printf ( "\n\n" );
  65.         
  66.     SqlBindByNum ( pSqlProcess, 1, szFirstName, BIND_CHAR );
  67.     SqlBindByNum ( pSqlProcess, 2, szLastName,  BIND_CHAR );
  68.     SqlBindByNum ( pSqlProcess, 3, szHomePhone, BIND_CHAR );
  69.     SqlBindByNum ( pSqlProcess, 4, szCity,        BIND_CHAR );
  70.     SqlBindByNum ( pSqlProcess, 5, szState,     BIND_CHAR );
  71.         
  72.     SqlOpenCursor  ( pSqlProcess );
  73.  
  74.     sRow = 0;
  75.  
  76.     while ( SqlFetchRow ( pSqlProcess ) )
  77.     {
  78.         sRow++;
  79.         printf ( "%3d.  %-12s  %-15s  %12s  %-12s  %2s\n",
  80.                  sRow, szFirstName, szLastName, szHomePhone,
  81.                  szCity, szState );
  82.  
  83.     }
  84.  
  85.     SqlCloseCursor ( pSqlProcess );
  86.     }
  87. }
  88.