Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> OCI question -- if you have souls please help!
Morning Dave,
what version of OCI are you using - the code you supplied looks very 'old style' to me. There is a chunk of my code below which will connect to a database using Oracle 8i/9i OCI. The code is an extract from a simple OCI application that I am working on using Borland's C++ compiler. The code is in C++ so what you are seeing is the member functions of a Window object that I'm using. Hopefully, you'll be able to extract the meat from mthe following code.
Also, much of the infernal casting that OCI needs has not been shown. Borland C++ compilers are quite able to determine that a cast will work or not, and advises so. I only have to cast when absolutely necessary - I get the impression that the example code & programs for OCI are written to MS Visual C++ standards - which is actually a contradiction as VC++ has no standards !
Cheers,
Norman.
#include "oci.h" #include <string.h> #include "mainwindow.h" //----------------------------------------------------------------------
//----------------------------------------------------------------------
#ifdef ORACLE_8I_ONWARDS
// Initialise the OCI enviroment Oracle 8i/9i style.
LogMessage("Creating OCI Environment - ", false);
if (OCIEnvCreate(&OCIParams.envhp,
OCI_DEFAULT, NULL, NULL, NULL, NULL, 0, NULL)) { LogMessage("failed."); return false; } else { LogMessage("ok.");
#else
// Initialise the OCI enviroment Oracle 8.0 style.
LogMessage("Initialising OCI - ", false);
if (OCIInitialize(OCI_DEFAULT,
NULL, NULL, NULL, NULL)) { LogMessage("failed."); return false; } else { LogMessage("ok.");
LogMessage("Initialising OCI Environment - ", false); if (OCIEnvInit(&OCIParams.envhp,
OCI_DEFAULT, 0, NULL)) { LogMessage("failed."); return false; } else { LogMessage("ok.");
LogMessage("Creating OCI error handle - ", false); if (OCIHandleAlloc(OCIParams.envhp,
reinterpret_cast<dvoid **>(&OCIParams.errhp), OCI_HTYPE_ERROR, 0, NULL)) { LogMessage("failed."); return false; } else { LogMessage("ok.");
LogMessage("Logging on to database - ", false); if (OCILogon(OCIParams.envhp,
OCIParams.errhp, &OCIParams.svchp, Username, strlen(Username), Password, strlen(Password), Service, strlen(Service))) { LogMessage("failed."); return false; } else { LogMessage("ok.");
// We must be connected if we got this far !
return true;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
LogMessage("Logging off - ", false); if (OCILogoff(OCIParams.svchp,
OCIParams.errhp)) { LogMessage("failed."); } else { LogMessage("ok.");
// Deallocate my handles ...
// There is no need to deallocate the Service Context handle as the
above
// call to OCILogoff deallocates it for us in a manner similar to
that in
// which OCILogon creates it for us.
LogMessage("Deallocating error handle - ", false); if (OCIHandleFree(OCIParams.errhp,
OCI_HTYPE_ERROR)) { LogMessage("failed."); } else { LogMessage("ok.");
// It is written that freeing the parent handle (the environment)
will also
// free all its children (the error). I have tested this and it is
true, but
// the examples in Oracle explicitly free all user allocated handles
- why ?
//
// If I change the order of freeing handles and free the environment
one
// first, freeing the error handle afterwards will fail - so it
looks as if
// the documentation is correct. However, I'm not a very trusting
soul, so I
// do it myself.
LogMessage("Deallocating environment handle - ", false); if (OCIHandleFree(OCIParams.envhp,
OCI_HTYPE_ENV)) { LogMessage("failed."); } else { LogMessage("ok.");
Tel: 0113 289 6265 Fax: 0113 289 3146 URL: http://www.Lynx-FS.com -------------------------------------Received on Tue May 13 2003 - 03:36:01 CDT
![]() |
![]() |