1 Reply Latest reply: Mar 23, 2012 11:17 AM by Steve.Clamage-Oracle RSS

    G++ compiler not regonizing embedded sql tags/keywords on Red hat 4.5

    865860
      Hi,

      i can compile a simple hello world script but what i want to achieve is to have embedded sql in the script as well but as soon as i do that i get the following errors for which i cant find a solution on the web:

      error: `EXEC' does not name a type
      error: `VARCHAR' does not name a type
      error: `username' was not declared in this scope
      error: expected `;' before "SQL"

      Any form of help will be appreciated.

      Regards,
      #include <iostream>
      #include <stdlib.h>
      #include <stdio.h>
      #include <string>
      #include <unistd.h>   
      #include <fstream>
      
      using namespace std;
      #define     UNAME_LEN 10
      #define     PWD_LEN   13
      
                        
      EXEC SQL INCLUDE sqlca; 
      EXEC SQL INCLUDE sqlda;
      EXEC SQL INCLUDE sqlcpr;
      
      
      EXEC SQL BEGIN DECLARE SECTION;
        VARCHAR username[UNAME_LEN];
        VARCHAR password[PWD_LEN];
        VARCHAR dbname[4];
      EXEC SQL END DECLARE SECTION;
      
      int main() {
      char hello[15];
        username.len = (unsigned short)strlen(strcpy((char *)username.arr, "xx"));
        password.len = (unsigned short)strlen(strcpy((char *)password.arr, "xx"));
        dbname.len = (unsigned short)strlen(strcpy((char *)dbname.arr, "xx"));
      
      EXEC SQL CONNECT :username IDENTIFIED BY :password USING :dbname;
      
      EXEC SQL SELECT 'Hello World' INTO :hello FROM DUAL;
      
      printf("%s\n", hello);
      
      EXEC SQL COMMIT RELEASE;
      
      return 0;
      }
        • 1. Re: G++ compiler not regonizing embedded sql tags/keywords on Red hat 4.5
          Steve.Clamage-Oracle
          This forum is about C++ programming in general, and using Oracle Solaris (formerly Sun) Studio C++ in particular.

          Embedded SQL is not part of standard C++, and is not supported by Studio C++. I don't know whether g++ has direct support for embedded SQL. You should ask about that in a g++ forum, or possibly in a Red Hat forum in your case.

          If you are trying to use SQL with Oracle Database, you need to compile the C++ source code with Pro*C, which translates embedded SQL into library calls, and links with the Oracle DB library. Although Pro*C is provided in Studio 12.3 as part of the OBI extensions, the best place to ask about Pro*C is in an Oracle database programming forum. You can start here:
          https://forums.oracle.com/forums/category.jspa?categoryID=18