Now that you understand the mechanics of creating an OCI XML application, we can examine the Update application’s Main function:
#include "xmlupdate.h" /*---------------------------Main function -----------------------------*/ int main(argc, argv) int argc; char *argv[]; { /* OCI Handles and Variables */ OCIEnv *envhp = (OCIEnv *) 0; OCIServer *srvhp = (OCIServer *) 0; OCISvcCtx *svchp = (OCISvcCtx *) 0; OCIError *errhp = (OCIError *) 0; OCISession *authp = (OCISession *) 0; OCIStmt *stmthp = (OCIStmt *) 0; /* database login information */ text *user=(text *)"SH"; text *password=(text *)"SH"; /*Service Name for DB instance if remote DB */ text *conn=(text *)"; /* Miscellaneous */ boolean tab_exists = TRUE; ub4 row = 1; if (argc < 3) { printf("\nUsage error: xmlupdate \"<SQL/XML Query>\" \"<XPath>\" \"<value>\"\n\n"); return OCI_ERROR; } /* Initialize the environment and allocate handles */ if (init_env_handle(&envhp, &svchp, &errhp, &srvhp, &authp, &stmthp)) { printf("FAILED: init_env_handle()!\n"); return OCI_ERROR; } /* Log on to the server and begin a session */ if (connect_server(srvhp, errhp, svchp, authp, user, password)) { printf("FAILED: connect_server()!\n"); cleanup(envhp); return OCI_ERROR; } /* Select an xmltype column by defining it to an xmltype instance, apply some OCIXMLType and unified DOM APIs */ row = 1; if (select_test_xml(envhp, svchp, errhp, stmthp, row, (text *)argv[1], (text *)argv[2], (text *)argv[3])) { printf("FAILED: select_test_xml()!\n"); disconnect_server(envhp, svchp, errhp, authp, srvhp, stmthp, tab_exists); return OCI_ERROR; } /* Detach from a server and clean up the environment */ disconnect_server(envhp, svchp, errhp, authp, srvhp, stmthp, tab_exists); return OCI_SUCCESS; }
Note that the application has the software steps of initialization; connecting to the database; submitting the query; performing the application logic on the results; and cleaning up before exiting. In the following sections, you will see the details of each of these steps as the application is built out.