home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbutil.zip / EXECSQL.ZIP / EXECSQL.CPP < prev    next >
C/C++ Source or Header  |  1993-10-26  |  2KB  |  82 lines

  1. // 
  2. // processed by precompiler  10-26-93  07:08:57
  3. // 
  4. #include <istring.hpp>
  5. #include <string.h>
  6. #include <fstream.h>
  7. //### EXEC SQL INCLUDE SQLCA;
  8.  #include <sqlda.h>   // sqlda structure 
  9. #include <sqlca.h>   // sqlca structre 
  10. #include <sqlaprep.h> // api(s) for most calls 
  11. #include <sqlenv.h>   // api(s) for start & stop db 
  12. sqlca sqlca; 
  13. typedef int  Boolean; 
  14. #define false 0
  15. #define true 1 
  16. Boolean _sqlfound = false;
  17. Boolean _sqlerror = false;
  18. Boolean _sqlwarn = false; 
  19. int _RC;
  20. const unsigned char sqla_program_id[40] = {
  21.        0x6f,0x41,0x41,0x42,0x41,0x45,0x43,0x43,0x45,0x44,
  22.        0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x78,0x65,0x63,
  23.        0x73,0x71,0x6c,0x20,0x63,0x41,0x36,0x49,0x48,0x61,
  24.        0x4b,0x4a,0x30,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
  25.  
  26.  
  27. //### EXEC SQL BEGIN DECLARE SECTION;
  28.      char    DBName[20];
  29.     char  SqlStr[1000];
  30. //### EXEC SQL END DECLARE SECTION;
  31.      
  32. void ProcessSQL(char *);            // prototype of process statement
  33.  
  34. void main(int nbr, char * argv[])
  35. {
  36.     ifstream fin;
  37.     IString input;
  38.     char inString[256];
  39.     fin.open(argv[1],ios::in);
  40.     if(!fin) {
  41.         cout << "invalid input file";
  42.         return;
  43.         }
  44.     while (fin.eof() ==0){                // do till end of file
  45.         input = "";
  46.         while (!input.includes(";")) // do to end of statement
  47.         {
  48.             fin.getline(inString,255);
  49.             input = input + inString;
  50.             if (!fin.eof() == 0)
  51.               break;
  52.         }
  53.         input.translate(";"," ");
  54.         ProcessSQL(input);    
  55.     }                                            // end of while not eof
  56. }     // end of main
  57.  
  58.  
  59. void ProcessSQL(char * s){
  60.     strset(SqlStr,0);
  61.     strcpy(SqlStr,s);
  62. //###     EXEC SQL EXECUTE IMMEDIATE :SqlStr;
  63.       sqlastrt(&sqla_program_id,NULL,&sqlca); 
  64.      _RC  = sqlasets(strlen( SqlStr),SqlStr,NULL);
  65.      sqlacall(23, 1, 0, 0,NULL); 
  66.      sqlastop(NULL); 
  67.     if(sqlca.sqlcode < 0){
  68.         sqlaintp(SqlStr,255,60,&sqlca);
  69.         cout << SqlStr;
  70.         }
  71. //###     EXEC SQL COMMIT WORK;    
  72.       sqlastrt(&sqla_program_id,NULL,&sqlca); 
  73.      sqlacall(21, 0, 0, 0,NULL); 
  74.      sqlastop(NULL); 
  75.     }
  76.     
  77.     
  78.     
  79.     
  80.  
  81.  
  82.