SQLAPI++ library

This is a discussion on SQLAPI++ library within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by CornedBee Unless you plan to use the Firebird database, I think you can ignore them. losing my ...

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by CornedBee View Post
    Unless you plan to use the Firebird database, I think you can ignore them.
    losing my mind here, when i build the properties i get lots of errors ... some of them are

    Code:
    3>c1xx : fatal error C1083: Cannot open source file: '..\..\..\src\backends\firebird\blob.cpp': No such file or directory
    3>common.cpp
    3>c1xx : fatal error C1083: Cannot open source file: '..\..\..\src\backends\firebird\common.cpp': No such file or directory
    I actually remove all the macros of the databases i won't need and only left oracle ... There's just no easy way to configure C++ and DB ...

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Sorry, I've never tried to build SOCI before. I've just seen it in use and liked the way it worked.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    Oracle's got there own OCCI libraries for MS Visual C++ 8/9 (2005/2008) or for g++ compiler's:

    http://www.oracle.com/technology/tec...cci/index.html

    Far as I know they are free to download and use to your heart's content.

    [edit]Those are for Oracle 10/11g databases.[/edit]
    from the occi readme file, could someone please explain step 3 & 4?

    1) Create a new sub-directory "vc8" under %ORACLE_HOME%\oci\lib\msvc

    2) Copy the .lib, .dll and .manifest files from this archive to
    %ORACLE_HOME%\oci\lib\msvc\vc8

    3) Include %ORACLE_HOME%\oci\lib\msvc\vc8 directory in the list of library
    directories when linking the application. Include oraocci10.lib or
    oraocci10d.lib, as appropriate, in the application link command.

    4) Ensure that %ORACLE_HOME%\oci\lib\msvc\vc8 is first in the PATH when
    running the application.
    Am really struggling to understand what they mean

  4. #19
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    3) Include %ORACLE_HOME%\oci\lib\msvc\vc8 directory in the list of library
    directories when linking the application. Include oraocci10.lib or
    oraocci10d.lib, as appropriate, in the application link command.
    This means you need to edit your project properties/options in Visual C++ to include the directory where you've placed these library files. Go to your project's properties: Project Properties->Configuration Properties->Linker->Additional Library Directories and type in the path to that folder in the space provided. This is for the static libraries to work.

    4) Ensure that %ORACLE_HOME%\oci\lib\msvc\vc8 is first in the PATH when
    running the application.
    This means you need to edit your computer's PATH settings to also include this directory/folder. For WinXP this is done by right clicking "My Computer" select the "Advanced" tab, then the "Environment Variables" button. Down in the "System Variables" area, you can scroll down till you see the "Path" variable; select (highlight) it and click on the "Edit" button to change the value and add the specified path above to the beginning of the existing value. I think this is for the dynamic libraries to work.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #20
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    Got your PM, I'm attaching my Oracle OCI related headers. They should work with the libraries you've downloaded from the Oracle site. It's a compressed archive file so rename it from .txt to .zip and unzip it. I'd suggest either unzipping it to the OCI/Include folder (on my machine it's C:\oracle\product\10.2.0\client_1\oci\include), or you could even maybe put it in with the compiler's headers (I think it's C:\Program Files\Microsoft Visual Studio 8\VC\include for my Visual Studio C++ 2005 installation).
    Attached Files Attached Files
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #21
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Quote Originally Posted by Perspective View Post
    ODBC is not part of the win32 api.
    Of course it is !
    See Win32 SQL* apis on MSDN !
    (and I don't talk about all the others Data Access Win32 api functions ...)

  7. #22
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    Got your PM, I'm attaching my Oracle OCI related headers. They should work with the libraries you've downloaded from the Oracle site. It's a compressed archive file so rename it from .txt to .zip and unzip it. I'd suggest either unzipping it to the OCI/Include folder (on my machine it's C:\oracle\product\10.2.0\client_1\oci\include), or you could even maybe put it in with the compiler's headers (I think it's C:\Program Files\Microsoft Visual Studio 8\VC\include for my Visual Studio C++ 2005 installation).
    Thanks hk, will try this out!

  8. #23
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    Got your PM, I'm attaching my Oracle OCI related headers. They should work with the libraries you've downloaded from the Oracle site. It's a compressed archive file so rename it from .txt to .zip and unzip it. I'd suggest either unzipping it to the OCI/Include folder (on my machine it's C:\oracle\product\10.2.0\client_1\oci\include), or you could even maybe put it in with the compiler's headers (I think it's C:\Program Files\Microsoft Visual Studio 8\VC\include for my Visual Studio C++ 2005 installation).
    Using an example, i tried including occi.h, but i get the following error

    Code:
    1>c:\c++ folder\dbtester\dbtester\connect.cpp(1) : fatal error C1083: Cannot open include file: 'occi.h': No such file or directory
    Here's how i've included it

    Code:
    #include <occi.h>
    #include <iostream>
    
    using namespace std;
    
    using namespace oracle::occi;
    
    const string sqlString("select empno, ename, hiredate from emp");
    
    const string dateFormat("DD-MON-YYYY HH24:MI:SS");
    
    int main(int argc, char **argv)
    
    {
        if (argc != 2)
        {
            cerr << "\nUsage: " << argv[0] << " <db-user-name>\n" << endl;
            exit(1);
        }
        
        // Initialize OracleServices
        
        DbManager* dbm = NULL;
        
        OracleServices* oras = NULL;
        
        Statement *stmt = NULL;
        
        ResultSet *resultSet = NULL;
        
        try
        {
            
            // Obtain OracleServices object with the default args.
            
            dbm = new DbManager(userName);
            
            oras = dbm->getOracleServices();
            
            // Obtain a cached connection
            
            Connection * conn = oras->connection();
            
            // Create a statement
            
            stmt = conn->createStatement(sqlString);
            
            int empno;
            
            string ename;
            
            Date hireDate;
            
            string dateAsString;
            
            // Execute query to get a resultset
            
            resultSet = stmt->executeQuery();
            
            while (resultSet->next())
            {
                
                empno = resultSet->getInt(1);  // get the first column returned by the query;
                
                ename = resultSet->getString(2);  // get the second column returned by the query
                
                hireDate = resultSet->getDate(3);  // get the third column returned by the query
                
                dateAsString="";
                
                //You cannot check for null until the data has been read
                
                if (resultSet->isNull(1))
                {
                    cout << "Employee num is null... " << endl;
                }
                if (resultSet->isNull(2))
                {
                    cout << "Employee name is null..." << endl;
                }
                if (resultSet->isNull(3))
                {
                    cout << "Hire date is null..." << endl;
                }
                else
                {
                    dateAsString=hireDate.toText(dateFormat);
                }
                cout << empno << "\t" << ename << "\t" << dateAsString << endl;
                
            }
            
            // Close ResultSet and Statement
            
            stmt->closeResultSet(resultSet);
            
            conn->terminateStatement(stmt);
            
            // Close Connection and OCCI Environment
            
            delete dbm;
            
        }
        catch (SQLException& ex)
        {
            if (dbm != NULL)
            {
                dbm->rollbackActions(ex, stmt, resultSet); // free resources and rollback transaction
            }
        }
        catch (ExoException& ex1)
        {
            cerr << "\nCaught ExoException:\n" << ex1.getExceptionText() << endl;
            exit(2);
        }
        
        return 0;
    }
    Here's where its location is ... C:\oraclexe\app\oracle\product\10.2.0\server\OCI\i nclude\occi.h

    How do i include it?

  9. #24
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    #1. You could hard code the path (not ideal)
    Code:
    #include "C:\oraclexe\app\oracle\product\10.2.0\server\OCI\include\occi.h"
    #2. ...Or you need to set the IDE to also have that path as an additional include folder:
    Go to "Project->Properties->Configuration Properties->C/C++->Additional Include Directories" and type in "C:\oraclexe\app\oracle\product\10.2.0\server\OCI\ include"
    Attached Images Attached Images  
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #25
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    #1. You could hard code the path (not ideal)
    Code:
    #include "C:\oraclexe\app\oracle\product\10.2.0\server\OCI\include\occi.h"
    #2. ...Or you need to set the IDE to also have that path as an additional include folder:
    Go to "Project->Properties->Configuration Properties->C/C++->Additional Include Directories" and type in "C:\oraclexe\app\oracle\product\10.2.0\server\OCI\ include"
    Thanx, i thought u were giving me your own code examples in the file you attached. I realized i already have those headers ... If you look at the example i just provided it uses DbManager which of cause is not part of occi headers... So kinda back to square 1 withouth any working examples

  11. #26
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    Yeah, I've never heard of that DbManager thing. I can give you a sample of something I worked on as a test program, just something to make sure I could connect to a database and actually read data from one of the tables. Things in blue are bits of code that I've changed to protect anything potentially sensitive (user names/service names,table names).

    I've highlighted the key database related stuff in green.

    Code:
    #include <occi.h>
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <iomanip>
    
    using namespace std;
    using namespace oracle::occi;
    
    #ifndef _DEBUG
    #pragma comment(lib,"oraocci10.lib")
    #else
    #pragma comment(lib,"oraocci10d.lib")
    #endif
    
    int main()
    {
        Environment * env = Environment::createEnvironment();
        Connection * conn = NULL;
        const string strUser = "YOUR_USER_HERE";       // User we connect as
        const string strConn = "YOUR_CONNECTION_HERE";   // Database connection
        string strPass;                                // Password for above
    
        // Make sure we get a connection to the database in question, otherwise quit.
        try
        {
            cout << "Enter password for user YOUR_USER_HERE: ";
            cin >> strPass;
            conn = env->createConnection(strUser,strPass,strConn);
        }
        catch (SQLException &sqlExcp)
        {
            cerr << sqlExcp.getErrorCode() << ": " << sqlExcp.getMessage()
    			 << "Press a key to continue..." << endl;
            cin.ignore();						// Ignore previous ws
            cin.get();
            Environment::terminateEnvironment(env);
            return EXIT_FAILURE;
        }
    
        // We should have a connection so we are connected to the database.
        if( conn )
        {
            cout << "Connected to the Oracle Database Server" << endl;
    		
            // Create the SQL statement we are going to be executing.
            Statement * stmt = NULL;
            stmt = conn->createStatement("SELECT ser, frq, xla, xlg FROM TABLE_NAME "
                                         "WHERE ser LIKE 'FAA 07%'");
            if( stmt )
            {
                // Execute the SQL statement and store the results for later.
                ResultSet * rs = stmt->executeQuery();
                int counter = 0;
    
                // Loop through retrieved records one-by-one and output the data.
                while( rs->next() )
                {
                    cout << "Result " << ++counter << ": "
                           << rs->getString(1) << ' '				// SER
                            << setw(10) << rs->getDouble(2) << ' '	// FRQ
                            << setw(10) << rs->getDouble(3) << ' '	// XLA
                            << setw(10) << rs->getDouble(4) << endl;	// XLG
                }
    
                // Cleanup, close the allocated result set.
                stmt->closeResultSet(rs);
            }
    
            // Cleanup, close the statement.
            conn->terminateStatement(stmt);
        }
        else
        {
            cout << "Could not connect to the Oracle Database Server"
                   << endl;
        }
    
        // More cleanup, terminate the connection to the database and the environment.
        env->terminateConnection(conn);
        Environment::terminateEnvironment(env);
    
        return 0;
    }
    Last edited by hk_mp5kpdw; 03-25-2009 at 06:56 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  12. #27
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    Yeah, I've never heard of that DbManager thing. I can give you a sample of something I worked on as a test program, just something to make sure I could connect to a database and actually read data from one of the tables. Things in blue are bits of code that I've changed to protect anything potentially sensitive (user names/service names,table names).

    I've highlighted the key database related stuff in green.

    Code:
    #include <occi.h>
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <iomanip>
    
    using namespace std;
    using namespace oracle::occi;
    
    #ifndef _DEBUG
    #pragma comment(lib,"oraocci10.lib")
    #else
    #pragma comment(lib,"oraocci10d.lib")
    #endif
    
    int main()
    {
        Environment * env = Environment::createEnvironment();
        Connection * conn = NULL;
        const string strUser = "YOUR_USER_HERE";       // User we connect as
        const string strConn = "YOUR_CONNECTION_HERE";   // Database connection
        string strPass;                                // Password for above
    
        // Make sure we get a connection to the database in question, otherwise quit.
        try
        {
            cout << "Enter password for user YOUR_USER_HERE: ";
            cin >> strPass;
            conn = env->createConnection(strUser,strPass,strConn);
        }
        catch (SQLException &sqlExcp)
        {
            cerr << sqlExcp.getErrorCode() << ": " << sqlExcp.getMessage()
    			 << "Press a key to continue..." << endl;
            cin.ignore();						// Ignore previous ws
            cin.get();
            Environment::terminateEnvironment(env);
            return EXIT_FAILURE;
        }
    
        // We should have a connection so we are connected to the database.
        if( conn )
        {
            cout << "Connected to the Oracle Database Server" << endl;
    		
            // Create the SQL statement we are going to be executing.
            Statement * stmt = NULL;
            stmt = conn->createStatement("SELECT ser, frq, xla, xlg FROM TABLE_NAME "
                                         "WHERE ser LIKE 'FAA 07%'");
            if( stmt )
            {
                // Execute the SQL statement and store the results for later.
                ResultSet * rs = stmt->executeQuery();
                int counter = 0;
    
                // Loop through retrieved records one-by-one and output the data.
                while( rs->next() )
                {
                    cout << "Result " << ++counter << ": "
                           << rs->getString(1) << ' '				// SER
                            << setw(10) << rs->getDouble(2) << ' '	// FRQ
                            << setw(10) << rs->getDouble(3) << ' '	// XLA
                            << setw(10) << rs->getDouble(4) << endl;	// XLG
                }
    
                // Cleanup, close the allocated result set.
                stmt->closeResultSet(rs);
            }
    
            // Cleanup, close the statement.
            conn->terminateStatement(stmt);
        }
        else
        {
            cout << "Could not connect to the Oracle Database Server"
                   << endl;
        }
    
        // More cleanup, terminate the connection to the database and the environment.
        env->terminateConnection(conn);
        Environment::terminateEnvironment(env);
    
        return 0;
    }
    cool thanks, will give this a shout and see how it goes...

    Cheers

  13. #28
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    Code:
        const string strUser = "YOUR_USER_HERE";       // User we connect as
        const string strConn = "YOUR_CONNECTION_HERE";   // Database connection
    is this
    Code:
    const string strConn  = "Driver={Oracle ODBC Driver}, Dbq=example, Uid=example, Pwd=example" ;
    about right?

  14. #29
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    For me, the "YOUR_CONNECTION_HERE" part is a value as taken directly from the TNS_NAMES.ORA file (on my system located under the C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN folder). This file contains all the connection information (IP addresses/database SIDs) for the different databases that I can connect to (you might have entries for several different databases on many different physical servers). As an example, my file might contain the following:
    Code:
    FOO =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XXX.XXX)(PORT = XXXX))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = BAR)
        )
      )
    Which basically means that on that particular machine, I have an alias called FOO which points to a database instance called BAR on IP address XXX.XXX.XXX.XXX. As this applies to your question "is this about right?", in my case the "YOUR_CONNECTION_HERE" string would simply be "FOO".

    [edit]You might also want to make sure you have a "TNS_ADMIN" entry for your system/user variables (right-click on "My Computer" then Properties->Advanced Tab->Environment Variables) which points to the folder where your TNS_NAMES.ORA is located.

    Don't know if this is absolutely required or not for sure.[/edit]
    Last edited by hk_mp5kpdw; 04-08-2009 at 11:28 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  15. #30
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    For me, the "YOUR_CONNECTION_HERE" part is a value as taken directly from the TNS_NAMES.ORA file (on my system located under the C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN folder). This file contains all the connection information (IP addresses/database SIDs) for the different databases that I can connect to (you might have entries for several different databases on many different physical servers). As an example, my file might contain the following:
    Code:
    FOO =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XXX.XXX)(PORT = XXXX))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = BAR)
        )
      )
    Which basically means that on that particular machine, I have an alias called FOO which points to a database instance called BAR on IP address XXX.XXX.XXX.XXX. As this applies to your question "is this about right?", in my case the "YOUR_CONNECTION_HERE" string would simply be "FOO".

    [edit]You might also want to make sure you have a "TNS_ADMIN" entry for your system/user variables (right-click on "My Computer" then Properties->Advanced Tab->Environment Variables) which points to the folder where your TNS_NAMES.ORA is located.

    Don't know if this is absolutely required or not for sure.[/edit]
    i ran SELECT ora_database_name FROM dual; and got the db name (XE) which is the same as yo indicate from the tns file ..thanks a lot

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 12:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21