home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbutil.zip / EXECSQL.ZIP / EXECSQL.SQC < prev    next >
Text File  |  1993-10-26  |  1KB  |  53 lines

  1. #include <istring.hpp>
  2. #include <string.h>
  3. #include <fstream.h>
  4. EXEC SQL INCLUDE SQLCA;
  5.  
  6. EXEC SQL BEGIN DECLARE SECTION;
  7.     char    DBName[20];
  8.     char  SqlStr[1000];
  9. EXEC SQL END DECLARE SECTION;
  10.     
  11. void ProcessSQL(char *);            // prototype of process statement
  12.  
  13. void main(int nbr, char * argv[])
  14. {
  15.     ifstream fin;
  16.     IString input;
  17.     char inString[256];
  18.     fin.open(argv[1],ios::in);
  19.     if(!fin) {
  20.         cout << "invalid input file";
  21.         return;
  22.         }
  23.     while (fin.eof() ==0){                // do till end of file
  24.         input = "";
  25.         while (!input.includes(";")) // do to end of statement
  26.         {
  27.             fin.getline(inString,255);
  28.             input = input + inString;
  29.             if (!fin.eof() == 0)
  30.               break;
  31.         }
  32.         input.translate(";"," ");
  33.         ProcessSQL(input);    
  34.     }                                            // end of while not eof
  35. }     // end of main
  36.  
  37.  
  38. void ProcessSQL(char * s){
  39.     strset(SqlStr,0);
  40.     strcpy(SqlStr,s);
  41.     EXEC SQL EXECUTE IMMEDIATE :SqlStr;
  42.     if(sqlca.sqlcode < 0){
  43.         sqlaintp(SqlStr,255,60,&sqlca);
  44.         cout << SqlStr;
  45.         }
  46.     EXEC SQL COMMIT WORK;    
  47.     }
  48.     
  49.     
  50.     
  51.     
  52.  
  53.