7 Replies Latest reply: Oct 16, 2012 3:22 PM by 967572 RSS

    How can we call methods with unicode support?

    967572
      Hello,

      I try to bring unicode support in my project and it seems that calling methods like "createConnection", etc. does not work with wstring.
      But, according the documentation, it is possible :

      [http://docs.oracle.com/cd/B19306_01/appdev.102/b14294/globalization.htm]

      //Call the Unicode version of createConnection by
      //passing widechar literals
      Connection *conn = env->createConnection(L"SCOTT",L"TIGER",L"");

      So why it doesn't work for me?
      I correctly set my Visual Studio project to enable Unicode support. All my code is ready and compiling fine, except about occi.

      Thank you,
      GMan

      Edited by: 964569 on 10 oct. 2012 13:17
        • 1. Re: How can we call methods with unicode support?
          jim dc
          Whats the actual error you are getting - and what versions of Visual Studio and Oracle Client are you on?
          • 2. Re: How can we call methods with unicode support?
            967572
            error C2664: 'oracle::occi::Connection oracle::occi::Environment::createConnection(const std::string &,const std::string &,const std::string &)' : cannot convert parameter 1 from 'const wchar_t ' to 'const std::string &'

            I am using Visual Studio 2012 and the InstantClient-basic-nt-11.2.0.3.0 with OCCI for Visual Studio 2010.
            I have a problem at runtime because I use OCCI for VS2010 in VS2012 (I guess). But this is not the problem because I know that is compiling fine without Unicode support. (I prepared my project and I am just waiting for the next OCCI version for VS2012. Do you know when it will be released?)

            Even, intellisense doesn't detect methods overloads using wstring, etc. Intellisense shows me overloads with std::string and UString, that's all.

            Edited by: 964569 on 13 oct. 2012 16:48
            • 3. Re: How can we call methods with unicode support?
              967572
              Update : With VS2012, I no longer have any problem at runtime without unicode.

              I just can't use unicode with OCCI. Why?! the documentation says that it is possible.
              • 4. Re: How can we call methods with unicode support?
                Mark Williams-Oracle
                I don't have VS2012 installed anywhere so I can't test with that specific version; however, in order to help ensure proper execution you must use the version of the C++ runtime library that matches the version of the OCCI library. Mixing versions is a recipe for disaster. There is currently no released version of OCCI for the VS2012 libraries that I know of.

                Having said the above, if you want to use the VS2010 library with the corresponding vc10 OCCI library and unicode, I believe you will need to disable the treatment of wchar_t as a built in type.

                To do this, perform the following for your VS project:

                (Project Name) Property Pages -> Configuration Properties -> C/C++ -> Language -> Treat WChar_t As Built in Type
                Change from "Yes (/Zc:wchar_t+)" to "No (/Zc:wchar_t-)"
                • 5. Re: How can we call methods with unicode support?
                  967572
                  Thank you for your answer!

                  I understand that using VS2012 with OCCI VS2010 could be problematic and resulting in ununderstandable errrors at runtime. For now, I am just trying very simple requests on HR with unicode to prepare me to bring unicode on another project (more complex). So, for now, the first thing I want, is that it compiles. Because that means I understand how to use unicode with OCCI. ^^

                  I tried your solution. It compiles fine now. Thank you. (-_-)b
                  At runtime, it seems my test application doesn't understand the connection string I provide. Working fine at runtime without unicode, now it can't resolve the connection string (I guess) and display the error "ORA-12543: TNS:destination host unreacheable".

                  Now, as you explained me, using VS2012 with OCCI for VS2010 is dangerous because I can't be totally sure about the errors at runtime... But may you have an idea.

                  Another question: Have you an idea about the release date of OCCI for VS2012? in 1, 2 (or more) months?

                  Thank you,
                  GMan
                  • 6. Re: How can we call methods with unicode support?
                    Mark Williams-Oracle
                    Perhaps you can take this very simple sample and use it to confirm it works in your environment. This was all done using 11.2.0.3 Oracle and VS2010.
                    #include <cstdlib>
                    #include <iostream>
                    #include <occi.h>
                    
                    using namespace std;
                    using namespace oracle::occi;
                    
                    int wmain(int argc, wchar_t* argv[])
                    {
                      // in order to avoid compile errors such as:
                      //   error C2664:
                      //   'oracle::occi::Connection *oracle::occi::Environment::createConnection(
                      //      const std::string &,const std::string &,const std::string &)' :
                      //   cannot convert parameter 1 from 'std::wstring' to 'const std::string &'
                      // disable treatment of wchar_t as built in type:
                      //   (Project Name) Configuration Properties -> C/C++ -> Language -> Treat WChar_t As Built in Type
                      //   Change from "Yes (/Zc:wchar_t)" to "No (/Zc:wchar_t-)"
                    
                      UString userid = L"hr";
                      UString passwd = L"hr";
                      UString server = L"//localhost:1521/V112";
                    
                      UString sql = L"select employee_id, first_name, last_name from employees order by last_name, first_name";
                    
                      Environment *env = Environment::createEnvironment("OCCIUTF16","OCCIUTF16");
                    
                      Connection *con = env->createConnection(userid, passwd, server);
                    
                      Statement *stmt = con->createStatement(sql);
                    
                      ResultSet *rs = stmt->executeQuery();
                    
                      while (rs->next())
                      {
                        wcout << rs->getInt(1) << L": ";
                        wcout << rs->getUString(2) << L" ";
                        wcout << rs->getUString(3) << endl;
                      }
                    
                      wcout << endl;
                    
                      stmt->closeResultSet(rs);
                    
                      con->terminateStatement(stmt);
                    
                      env->terminateConnection(con);
                    
                      Environment::terminateEnvironment(env);
                    
                      wcout << L"ENTER to terminate...";
                      wcin.get();
                    
                      return 0;
                    }
                    Sorry, I do not know about the release timeline for a version of OCCI that supports VS2012.
                    • 7. Re: How can we call methods with unicode support?
                      967572
                      Damn it! I forgot to uncomment "Environment :: createEnvironment (" OCCIUTF16 "," OCCIUTF16 ")" after doing my tests. I totally forgot that I commented this line in my code.
                      Now it works great!

                      Thank you very much for your help! (^-^)b