RE: [cx-oracle-users] Re: Choosing client libraries
Brought to you by:
atuining
From: Amaury F. <Ama...@gl...> - 2006-01-24 16:14:57
|
Anthony wrote: > To understand what I mean, try loading a cx_Oracle module compiled=20 > against Oracle 9i with an Oracle 8i client. You will get a=20 > messagebox indicating that the symbol OCISessionGet could=20 > not be located in oci.dll. If you have a suggestion about how=20 > to get around that problem __without__ involving a huge=20 > rewrite of cx_Oracle to call everything dynamically I'm all ears. This is what I did some years ago with the old OCI7 function. At the time, it was the only way to have a program run with=20 both Oracle7 and Oracle 8i, even if you use only functions=20 that belong to both libraries. My solution is: - cx_Oracle does not link with any Oracle library. - instead, we provide an implementation for each OCI* function, which simply loads dynamically the Oracle client, bind the function, and call it. (I just counted 54 different OCI functions in cx_Oracle!) Below is a sample, for the old 'olog' function. This change would not touch any existing cx_Oracle file, Only one more file is compiled and linked with cx_Oracle. I think the same trick would also work on some other platforms. At the end, we could have a "dynamic" version of cx_Oracle! ----------------------------- typedef sword (*OCIPROC)(); HINSTANCE hOCI =3D NULL; // Find the OCI library HINSTANCE check_dll() { // This could be enhanced to choose the desired library if (!hOCI) hOCI =3D LoadLibrary("oci.dll"); return hOCI; } // Load the OCI library and find the function OCIPROC check_function(char *name, OCIPROC *fn) { if( *fn ) return *fn; if( !check_dll() ) return NULL; *fn =3D (OCIPROC)GetProcAddress( hOCI, name ); return *fn; } // All OCI functions must be written like this sword olog(LDA *lda, ub1 *hda, text *uid, sword uidl, text *pswd, sword pswdl, text *conn, sword connl, ub4 mode) { static OCIPROC p_olog=3DNULL; if( check_function("olog", &p_olog)) return p_olog(lda,hda,uid,uidl,pswd,pswdl,conn,connl,mode); else return 1; // error } --=20 Amaury Forgeot d'Arc Ubix Development www.ubitrade.com |