intf(stderr, "OCI_NO_DATA\n"); break; case OCI_INVALID_HANDLE: fprintf(stderr, "OCI_INVALID_HANDLE\n"); break; case OCI_STILL_EXECUTING: fprintf(stderr, "OCI_STILL_EXECUTING\n"); break; case OCI_CONTINUE: fprintf(stderr, "OCI_CONTINUE\n"); break; default: break; }
if (status != OCI_SUCCESS && status != OCI_SUCCESS_WITH_INFO) disconnect(); }
/******************************************************************************* ** ** Routine: connect ** ** Description: Connects to oracle, and set error routine sqlerror. ** *******************************************************************************/ void WReadAndWriteGeometry::connect(char *username, char *password, char *connectstring) {
// int maxsz = 50 ; /* 50% increase ? */ // int optsz = 2048000 ; /* 2000 K bytes */ // int curmaxsz, curoptsz;
/* Allocate and initialize OCI environment handle, envhp */ OCIInitialize((ub4) OCI_OBJECT, (dvoid *)0, (dvoid * (*)(dvoid *,size_t)) 0, (dvoid * (*)(dvoid *, dvoid *, size_t)) 0, (void (*)(dvoid *, dvoid *)) 0 ); OCIEnvInit(&envhp, (ub4)OCI_DEFAULT, (size_t)0, (dvoid **)0);
/* ** Initialize error report handle, errhp ** Initialize sever context handle, srvhp */ OCIHandleAlloc((dvoid *)envhp, (dvoid **)&errhp, (ub4)OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0); OCIHandleAlloc((dvoid *)envhp, (dvoid **)&srvhp, (ub4)OCI_HTYPE_SERVER, (size_t)0, (dvoid **)0); OCIServerAttach(srvhp, errhp, (text *)connectstring, (sb4)strlen(connectstring), (ub4)OCI_DEFAULT);
/* initialize svchp */ OCIHandleAlloc((dvoid *)envhp, (dvoid **)&svchp, (ub4)OCI_HTYPE_SVCCTX, (size_t)0, (dvoid **)0); OCIAttrSet((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX, (dvoid *)srvhp, (ub4)0, (ub4)OCI_ATTR_SERVER, errhp);
/* initialize usrhp */ OCIHandleAlloc((dvoid *)envhp, (dvoid **)&usrhp, (ub4)OCI_HTYPE_SESSION, (size_t)0, (dvoid **)0); OCIAttrSet((dvoid *)usrhp, (ub4)OCI_HTYPE_SESSION, (dvoid *)username, (ub4)strlen(username), (ub4)OCI_ATTR_USERNAME, errhp); OCIAttrSet((dvoid *)usrhp, (ub4)OCI_HTYPE_SESSION, (dvoid *)password, (ub4)strlen(password), (ub4)OCI_ATTR_PASSWORD, errhp);
/* session begins */ checkerr(errhp, OCISessionBegin(svchp, errhp, usrhp, OCI_CRED_RDBMS, OCI_DEFAULT)); OCIAttrSet((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX, (dvoid *)usrhp, (ub4)0, (ub4)OCI_ATTR_SESSION, errhp);
/* initialize stmthp */ checkerr(errhp, OCIHandleAlloc((dvoid *)envhp, (dvoid **)&stmthp, (ub4)OCI_HTYPE_STMT, (size_t)0, (dvoid **)0));
/* describe spatial object types */ checkerr(errhp, OCIHandleAlloc(envhp, (dvoid **)&dschp, (ub4)OCI_HTYPE_DESCRIBE, (size_t)0, (dvoid **)0));
geom_tdo = get_tdo(SDO_GEOMETRY);
printf ("\nConnected to Oracle.\n"); }
/******************************************************************************* ** ** Routine: disconnect ** ** Description: Disconnect from Oracle ** *******************************************************************************/ void WReadAndWriteGeometry::disconnect(void) { /* finalize type descriptor */ checkerr(errhp, OCIHandleFree((dvoid *)dschp, (ub4)OCI_HTYPE_DESCRIBE));
/* finalize stmthp */ OCIHandleFree((dvoid *)stmthp, (ub4)OCI_HTYPE_STMT);
/* session ends */ OCISessionEnd(svchp, errhp, usrhp, (ub4)OCI_DEFAULT); OCIServerDetach(srvhp, errhp, (ub4)OCI_DEFAULT);
/* finalize svchp, srvhp, and errhp */ OCIHandleFree((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX); OCIHandleFree((dvoid *)srvhp, (ub4)OCI_HTYPE_SERVER); OCIHandleFree((dvoid *)errhp, (ub4)OCI_HTYPE_ERROR);
printf ("\nDisconnected from Oracle.\n"); exit(0); }
/****************************************************************************** ** ** Routine: get_tdo ** ** Description: Returns the ** ******************************************************************************/ OCIType *WReadAndWriteGeometry::get_tdo(char *typeName) { OCIParam *paramp = NULL; OCIRef *type_ref = NULL; OCIType *tdo = NULL;
checkerr(errhp, OCIDescribeAny(svchp, errhp, (text *)typeName, (ub4)strlen((char *)typeName), OCI_OTYPE_NAME, (ub1)1, (ub1)OCI_PTYPE_TYPE, dschp)); checkerr(errhp, OCIAttrGet((dvoid *)dschp, (ub4)OCI_HTYPE_DESCRIBE, (dvoid *)¶mp, (ub4 *)0, (ub4)OCI_ATTR_PARAM, errhp)); checkerr(errhp, OCIAttrGet((dvoid *)paramp, (ub4)OCI_DTYPE_PARAM, (dvoid *)&type_ref, (ub4 *)0, (ub4)OCI_ATTR_REF_TDO, errhp)); checkerr(errhp, OCIObjectPin(envhp, errhp, type_ref, (OCIComplexObject *)0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, (dvoid **)&tdo)); if (!tdo) { fprintf(stderr, "Null tdo returned for type %s.\n", typeName); disconnect(); }
return tdo; }
/******************************************************************************* ** ** Routine: process_data ** ** Description: Process the data for current host array fetch. ** *******************************************************************************/ void WReadAndWriteGeometry::process_data(int num_dimensions, char *id_column, int rows_to_process, int *rows_processed) { int row; double double_gid;
for (row = 0; row < rows_to_process; row++, (*rows_processed)++) { /* ** Get ID_COLUMN */ checkerr(errhp, OCINumberToReal(errhp, &(global_gid[row]), (uword)sizeof(double), (dvoid *)&double_gid));
printf("\n%s %.5lf\n", id_column, double_gid);
sc_ops_init_geometry (global_geom_obj[row], global_geom_ind[row], num_dimensions);
if (sc_ops_geom_null()) { printf ("OBJECT IS NULL\n"); fflush (stdout); } else { sc_ops_get_gtype (); sc_ops_get_sdo_point ();
/* Loop through and print all the elements for this geometry */ while (sc_ops_next_elem ()) { switch (sc_ops_get_element_type ()) { case 1: sc_ops_get_type1(); break; case 2: sc_ops_get_type2(); break; case 3: sc_ops_get_type3(); break; case 4: sc_ops_get_type4(); break; case 5: sc_ops_get_type5(); break; } }
/* free the spatial object instance */ checkerr(errhp, OCIObjectFree(envhp, errhp, (dvoid *)global_geom_obj[row], (ub2)OCI_OBJECTFREE_FORCE)); global_geom_obj[row] = NULL; } } /* end of for-loop: row */ }
/******************************************************************************* ** ** Routine: read_geometries ** ** Description: ** *******************************************************************************/ void WReadAndWriteGeometry::read_geometries (char *table, char *geom_column, char *id_column, int num_dimensions) { int nrows = 0, rows_fetched = 0, rows_processed = 0, rows_to_process = 0; char query[100]; sword status; boolean has_more_data = TRUE; OCIDefine *defn1p = NULL, *defn2p = NULL;
/* construct query */ sprintf(query, "SELECT %s, %s FROM %s", id_column, geom_column, table);
/* par 上一页 [1] [2] [3] [4] [5] 下一页 没有相关教程
|