Setting Up the OCI Application Environment
To build OCI XML applications, you need to set up the necessary headers and libraries and make files. Fortunately, you already have these items if you have installed the companion CD-ROM and specified as the destination directory $ORACLE_HOME on Unix or %ORACLE_HOME% on Windows.
The OCI XML Application Headers
The headers in Oracle Database 10g are installed into your Oracle Home by performing a companion CD installation. Once you have done this, you will have two directories that include the necessary header files: $ORACLE_HOME/rdbms/public and $ORACLE_HOME/xdk/include on Unix, and %ORACLE_HOME%/oci/include and %ORACLE_HOME%/xdk/include on Windows. The following is xmlupdate.h, the application header file that lists the required Oracle headers along with the application functions:
#ifndef STDIO
#include <stdio.h>
#endif
#ifndef STDLIB
#include <stdlib.h>
#endif
#ifndef STRING
#include <string.h>
#endif
#ifndef OCIAP_ORACLE
#include <ociap.h>
#endif
#ifndef XML_ORACLE
#include <xml.h>
#endif
/*----------------- End of including files -----------------*/
/*----------------- Public Constants and Variables ---------*/
/* constants */
#define MAXBUFLEN 2000
#define SCHEMA "SYS"
#define TYPE "XMLTYPE"
/*----------------- End of Constants and Variables -----------------*/
/*--------------------- Functions Declaration --------------------*/
int main(/*_ int argc, char *argv[] _*/);
static void checkerr(/*_ OCIError *errhp, sword status _*/);
static void cleanup(/*_ OCIEnv *envhp _*/);
static sb4 connect_server(/*_ OCIServer *srvhp, OCIError *errhp,
OCISvcCtx *svchp, OCISession *authp, text *user, text *password _*/);
static void disconnect_server(/*_ OCIEnv *envhp, OCISvcCtx *svchp,
OCIError errhp, OCISession *authp, OCIServer *srvhp, OCIStmt *stmthp,
boolean tab_exists _*/);
static sb4 init_env_handle(/*_ OCIEnv **envhp, OCISvcCtx **svchp,
OCIError *errhp, OCIServer **svrhp, OCISession **authp,
OCIStmt **stmthp _*/);
static sb4 select_xml(/*_ OCIEnv *envhp, OCISvcCtx *svchp,
OCIError *errhp, OCIStmt *stmthp, ub4 row, text *sel, text*xpath,
text *value_*/);
static sb4 do_xml(/*_ OCIEnv *envhp, OCISvcCtx *svchp,
OCIError *errhp, OCIXMLType *xml, text *xsl_file,
text *xpathexpr, text *value _*/);
int update_xml(/* struct xmlctx *xctx, xmldocnode *doc,
text *xpathexpr, text *value;_*/);
/*----------------- End of Functions Declaration ----------------*/
Note that while there are only two explicit Oracle header files, ociap.h and xml.h, they include others from their respective directories. We discuss the functions when we get to the code throughout the chapter.
The OCI XML Application Libraries
OCI applications are dynamically linked on both Unix and Windows using libclntsh.so, located in $ORACLE_HOME/lib32 on Unix, and oci.lib/ociw32.lib, located in %ORACLE_HOME%\oci\lib\Msvc on Windows. In the past the Solaris library has been in the lib directory, but since Oracle Database 10g is now only a 64-bit release, the 32-bit libraries are located in their own directory. On Windows you also need to link with the user32.lib, kernel32.lib, msvcrt.lib, advapi32.lib, oldnames.lib, and winmm.lib Windows libraries.
The OCI libraries do not contain the XML APIs; therefore, you also need to link with libxml10.a on Unix and oraxml10.lib on Windows. The Unix library is not a shared one like the OCI library and thus the objects you need will be pulled into your executable.
The OCI XML Application Make Files
As previously mentioned, the make files necessary to compile and link your application are provided with the database. On Unix this make file is demo_rdbms.mk, and it resides in your $ORACLE_HOME/rdbms/demo directory. This is a complicated make file because it works for various builds and thus you need a specific command line for our example:
make -f demo_rdbms32.mk build EXE=xmlupdate OBJS="xmlupdate.o"
Now, this make file includes $ORACLE_HOME/rdbms/lib/env_rdbms.mk, which includes the actual compile and link lines. Therefore, to ensure that your XML library is linked, you need to add libxml10.a to the end of the OCISHAREDLIBS variable as follows:
OCISHAREDLIBS=$(LLIBCLNTSH) $(LDLIBS) $(LLIBTHREAD) -lxml10
On Windows the make file is make.bat and is located in the %ORACLE_HOME%\oci\samples directory. Only one section is used for stand-alone applications, as follows, with oraxml10.lib added to the link portion:
cl -I%ORACLE_HOME%\oci\include -I. -D_DLL -D_MT %1.c /link
/LIBPATH:%ORACLE_HOME%\oci\lib\msvc oci.lib kernel32.lib msvcrt.lib
%ORACLE_HOME\Lib\Oraxml10.lib /nod:libc
This section is called with the following command line for our example:
make xmlupdate