6 Replies Latest reply on Nov 9, 2004 5:32 AM by 294787

    My First VC++ and OCCI report Error

    294787
      I create a window console application in Visual C++, and
      Add $ORAHOME\oci\include directory for include and $ORAHOME\oci\lib\msvc\vc6 for library. Then I paste "A Simple Useful OCCI Program" code from Oracle OCCI page to main(), then #include "occi.h". Following are codes:

      ---------------------------------------------------
      #include "stdafx.h"
      #include "occi.h"
      #include <iostream.h>

      int main(int argc, char* argv[])
      {
      //create environment and connection
           Environment* env = Environment::createEnvironment();
           Connection* conn = env->createConnection( "scott", "tiger" );

           cout << "Environment and Connection created" << endl;
           
           //execute a SQL statement
           Statement* stmt = conn->createStatement();
           stmt->setSQL("INSERT into FRUITS (fruit, amt) VALUES ('apple', 10)");
           stmt->executeUpdate();
           conn->terminateStatement(stmt);
           
           //terminate environment and connection
           env->terminateConnection(conn);
           Environment::terminateEnvironment(env);
           cout << "Environment and Connection terminated" << endl;

           return 0;
      }
      ---------------------------------------------------

      When compiled, report following errors:

      ------------------------------------------------
      -------------------Configuration: OCCIFirst - Win32 Debug--------------------
      Compiling...
      OCCIFirst.cpp
      d:\orant\product\10.1.0\ora10g\oci\include\occicontrol.h(1526) : error C2995: 'getVector' : template function has already been defined
      d:\orant\product\10.1.0\ora10g\oci\include\occicommon.h(519) : see declaration of 'getVector'
      d:\orant\product\10.1.0\ora10g\oci\include\occicontrol.h(1630) : fatal error C1903: unable to recover from previous error(s); stopping compilation
      Error executing cl.exe.

      OCCIFirst.exe - 2 error(s), 0 warning(s)
      ---------------------------------------------

      I'm new to OCCI, anyone here help to solve the problem, so that I can go on with OCCI

      Richard Lee
        • 1. Re: My First VC++ and OCCI report Error
          82532
          Search the forum for "template function has already been defined"

          You are missing a preprocessor #define

          (WIN32COMMON to be exact).
          • 2. Re: My First VC++ and OCCI report Error
            294787
            Hi, mark

            Thank you for your help on my question.
            However, I add #define, the compiler message are still the same. Following are codes:

            ---------------------------
            // OCCIFirst.cpp : Defines the entry point for the console application.
            //

            #define WIN32COMMON

            /*
            #ifdef WIN32COMMON
            template <class T>
            void getVector( ResultSet *rs, unsigned int index,
            OCCI_STD_NAMESPACE::vector< T > &vect);
            #else
            template <class T>
            void getVector( ResultSet *rs, unsigned int index,
            OCCI_STD_NAMESPACE::vector< T* > &vect);
            #endif
            */

            #include "stdafx.h"
            #include <iostream.h>
            #include "occi.h"

            int main(int argc, char* argv[])
            {
            //create environment and connection
                 Environment* env = Environment::createEnvironment();
                 Connection* conn = env->createConnection( "scott", "tiger" );

                 cout << "Environment and Connection created" << endl;
                 
                 //execute a SQL statement
                 Statement* stmt = conn->createStatement();
                 stmt->setSQL("INSERT into FRUITS (fruit, amt) VALUES ('apple', 10)");
                 stmt->executeUpdate();
                 conn->terminateStatement(stmt);
                 
                 //terminate environment and connection
                 env->terminateConnection(conn);
                 Environment::terminateEnvironment(env);
                 cout << "Environment and Connection terminated" << endl;

                 return 0;
            }

            ----------------------------

            Please help to solve the problem.

            Richard lee
            • 3. Re: My First VC++ and OCCI report Error
              82532
              <sigh>

              You didn't do the search and read the full solution did you? This was fully explained in another thread which is why I suggested using the search button :)

              You need to set this as at PREPROCESSOR level in the project/compiler settings.
              • 4. Re: My First VC++ and OCCI report Error
                294787
                Hi, mark tomlinson

                Following your more detailed instruction, getVector problem has been solved. However there are other questions appears.
                ----------------------------------------------------------
                D:\OCCIFirst\OCCIFirst.cpp(26) : error C2065: 'Environment' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(26) : error C2065: 'env' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(26) : error C2653: 'Environment' : is not a class or namespace name
                D:\OCCIFirst\OCCIFirst.cpp(26) : error C2065: 'createEnvironment' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(26) : error C2106: '=' : left operand must be l-value
                D:\OCCIFirst\OCCIFirst.cpp(27) : error C2065: 'Connection' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(27) : error C2065: 'conn' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(27) : error C2227: left of '->createConnection' must point to class/struct/union
                D:\OCCIFirst\OCCIFirst.cpp(32) : error C2065: 'Statement' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(32) : error C2065: 'stmt' : undeclared identifier
                D:\OCCIFirst\OCCIFirst.cpp(32) : error C2227: left of '->createStatement' must point to class/struct/union
                D:\OCCIFirst\OCCIFirst.cpp(33) : error C2227: left of '->setSQL' must point to class/struct/union
                D:\OCCIFirst\OCCIFirst.cpp(34) : error C2227: left of '->executeUpdate' must point to class/struct/union
                D:\OCCIFirst\OCCIFirst.cpp(35) : error C2227: left of '->terminateStatement' must point to class/struct/union
                D:\OCCIFirst\OCCIFirst.cpp(38) : error C2227: left of '->terminateConnection' must point to class/struct/union
                D:\OCCIFirst\OCCIFirst.cpp(39) : error C2653: 'Environment' : is not a class or namespace name
                D:\OCCIFirst\OCCIFirst.cpp(39) : error C2065: 'terminateEnvironment' : undeclared identifier
                ---------------------------------------------------------

                This time I search all related threads in this forum, and do following settings:

                Project->Settings->Links->Category->Input:
                add Object/library modules: oraocci10.lib
                and
                add Addtional library path :
                D:\orant\product\10.1.0\ora10g\oci\lib\msvc\vc6

                And from my first message, you could know I'll set include and library in Tools->Options correctly. Compile also report above errors;

                I'd like to thanks for your generous help.
                And sorry for my poor capability, I'm not familiar with
                VC++ IDE. Please again help to solve the problem.

                Richard lee
                • 5. Re: My First VC++ and OCCI report Error
                  Shiyer-Oracle
                  Since all OCCI classes are declared in the oracle::occi namespace, you need to add :

                  using namespace oracle::occi;

                  Regards,
                  Shankar
                  • 6. Re: My First VC++ and OCCI report Error
                    294787
                    Hi, Shankar Iyer

                    Thank you for your instruction. it worked, and my first OCCI + VC program run smoothly, with this progress, I could go on with OCCI+VC

                    Richard lee