Oracle Space Database Read and Writing

xiaoxiao2021-03-06  76

This is a console application, including 3 files. Rewinding according to a C program on the Oracle technology, the role: uses OCI to read and write Oracle spatial data.

/ / ---------------------------------- // Main.cpp: Defines the entry point of the console application. // -------------------------------------------- # include "WreadanDwriteMetry.h"

INT_TMAIN (int Argc, _tchar * argv []) {WreadanDwriteMetry WJJ ("TXK", "MLIB", "147"); wjj.read_geometries ("B562D8C5E4C81D0", "Geoloc", "Mi_Prinx", 1); Return 0 }

/ / ---------------------------------- // WreadanDwriteometry.h // --------------------------------------------- - # ix (! Defined (WreadanDwriteometry_h) # define WreadanDwriteMetry_H

#pragma Comment (Lib, "OCI.LIB") #pragma Comment (Lib, "Ociw32.Lib") #pragma Comment (Lib, "OraoCCI9.LIB")

#ifndef oci_oracle # include #include #ENDIF

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------- Public Types and constants ------------------- -------------------------------------------------- ------ * / # define ARRAY_SIZE 32 # define TYPE_OWNER "MDSYS" #define SDO_ORDINATE_ARRAY TYPE_OWNER ".SDO_ORDINATE_ARRAY" #define SDO_ELEM_INFO_ARRAY TYPE_OWNER ".SDO_ELEM_INFO_ARRAY" #define SDO_GEOMETRY TYPE_OWNER ".SDO_GEOMETRY"

/ ************************************************** *********************** / / * TYPE Definitions * // ************************** *********************************************************** ***** / STRUCT SDO_POINT_TYPE {OCINUMBER X; OCINUMBER Y; OCINUMBER Z;}; typedef struct SDO_POINT_TYPE SDO_POINT_TYPE;

typedef OCIArray sdo_elem_info_array; typedef OCIArray sdo_ordinate_array; struct sdo_geometry {OCINumber sdo_gtype; OCINumber sdo_srid; sdo_point_type sdo_point; OCIArray * sdo_elem_info; OCIArray * sdo_ordinates;};

Typedef struct sdo_geometry sdo_geometry_type;

/ ***** Indicator Structures for SDO_GEMETRY_TYPE *** /

Struct SDO_POINT_TYPE_IND {OCIIND _TOMIC; OCIIND X; OCIIND Y; OCIIND Z;}; type_indef struct SDO_POINT_TYPE_IND SDO_POINT_TYPE_IND;

struct SDO_GEOMETRY_ind {OCIInd _atomic; OCIInd sdo_gtype; OCIInd sdo_srid; struct sdo_point_type_ind sdo_point; OCIInd sdo_elem_info; OCIInd sdo_ordinates;}; typedef struct SDO_GEOMETRY_ind SDO_GEOMETRY_ind;

/ ************************************************** *********************** / / * Class Definitions * // ***************** *********************************************************** ***** / class WReadAndWriteGeometry {public: WReadAndWriteGeometry (char * username, char * password, char * connectstring); ~ WReadAndWriteGeometry (); void read_geometries (char * table, char * geom_column, char * id_column, int num_dimensions); Void Write_geometries ();

protected: void checkerr (OCIError * errhp, sword status); void connect (char * username, char * password, char * connectstring); void disconnect (void); OCIType * get_tdo (char * typeName); void process_data (int num_dimensions, CHAR * ID_COLUMN, int ROWS_TO_PROCESS, INT * ROWS_PROCESSED;

protected: int sc_ops_geom_null (void); void sc_ops_init_geometry (SDO_GEOMETRY_TYPE *, SDO_GEOMETRY_ind *, int); void sc_ops_get_gtype (void); void sc_ops_get_sdo_point (void); int sc_ops_next_elem (void); ub4 sc_ops_get_element_type (void); void sc_ops_get_type1 (void); void sc_ops_get_type2 (void); void sc_ops_get_type3 (void); void sc_ops_get_type4 (void); void sc_ops_get_type5 (void); ub4 get_interpretation (void); void get_ordinates (int starting_offset, int ending_offset); int get_next_ending_offset (int processing_type_4or5); int get_next_starting_offset ( INT read_varray); private: Ocienv * envhp; / * OCI general handles * / ocier * errhp;

OciServer * SRVHP; OCISVCCTX * SVCHP; OCISESSION * USRHP; OCIDESCRIBE * DSCHP;

When GEOMETRY // read data, private variables required: OCINumber global_gid [ARRAY_SIZE]; OCIType * geom_tdo; SDO_GEOMETRY_TYPE * global_geom_obj [ARRAY_SIZE]; / * spatial object buffer * / SDO_GEOMETRY_ind * global_geom_ind [ARRAY_SIZE]; / * Object indicator * /

When writing Geometry data, the variables required for the required variables: OCITY * ELEM_INFO_TDO; / * VARRAYS AND THE TEPE DESCRIPTORS * / OCIARRAY * ELEM_INFO; OCITY * Ordinates_TDO; OCIARRAY * Ordinates;

private: SDO_GEOMETRY_TYPE * m_geom_obj; SDO_GEOMETRY_ind * m_geom_ind; int global_num_dimensions; int global_elem_index; int global_ending_offset; int global_nelems; int global_nords; int global_first_elem;

}; # ENDIF

/ / ---------------------------------- // WreadanDwriteometry.cpp // --------------------------------------------- - # include #include #include #include #include using namespace std;

#include "wreadandWriteMetry.h"

STATIC DOUBLE TEST_ORDINATES [] = {0, 0, 1, 1}; / ***************************************** *********************************************************** Routine: wreadandwritegethometry **** Description: Constructor ************************************************************* ************************************************************* / WREADANDWRITEMETRY :: WreadanDwriteMetry (char * Username, char * password, char * connectstring) {dschp = null; geom_tdo = null; elem_info_tdo = null; ordinates_tdo = null;

Global_ending_offset = -1;

For (int i = 0; I

Connect (username, password, connectstring);

/ ************************************************** ********************************* ROUTINE: ~ WREADANDWRITEMETRY **** DESCRIPTION: Destructor *** *********************************************************** ************************************ / WREADANDWRITEMETRY :: ~ wreadAndWriteMetry () {disconnect ();}

/ ************************************************** ******************************** ROUTINE: Checkerr **** Description: Error Message Routine **** *********************************************************** ************************************* / VOID WREADANDWRITEMETRY :: CheckerR (OcierR) {text errbuf [512]; SB4 Errcode = 0;

switch (status) {case OCI_SUCCESS: break; case OCI_SUCCESS_WITH_INFO: fprintf (stderr, "OCI_SUCCESS_WITH_INFO / n"); break; case OCI_ERROR: OCIErrorGet ((dvoid *) errhp, (ub4) 1, (text *) NULL, & errcode, Errbuf, (UB4) SIZEOF (ERRBUF), OCI_HTYPE_ERROR); FPRINTF (stderr, "%. * S / N", 512, errbuf); Break; Case Oci_need_data: fprintf (stderr, "oci_need_data / n"); Break; Case OCI_NO_DATA: fprintf (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 Runtine SQLERROR. ************************************************************************************************************************************************************************************************************************** ****************************************** / VOID WREADANDWRITEMETRY :: Connect (Char * Username, Char * Password, Char * connectionString) {

// 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 WREADANDWRITEMETRY :: Disconnect (void) {/ * femance type descriptor * / checkerr (errom, ocihandlefree) (DVOID *) DSCHP, (UB4) OCI_HTYPE_DESCRIBE)); / * Finalize Stmthp * / OCIHANDLEFREE ((DVOID *) Stmthp, (UB4) OCI_HTYPE_STMT);

/ * session ends * / ocisesndend (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 ******* *********************************************************** ************************ / OCITY * WREADANDANDWRITEMETRY: 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 *) & paramp, (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", typeename; disconnect ();} returnit

/ ************************************************** ********************************* ROUTINE: Process_Data **** Description: Process The Data For Current Host Array Fetch. ****************************************************************** ****************************************** / VOID WREADADWRITEMETRY :: Process_Data (int Num_dimns, char * id_column, int rows_to_process, INT * ROWS_PROCESSED) {INT Row; double double_gID;

For (Row = 0; ROW

Printf ("/ N% S% .5LF / N", ID_COLUMN, DOUBLE_GID);

SC_OPS_INIT_GEMETRY (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 WREADANDWRITEMETRY:: 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)

/ * Parse Query * / Checkerr (Errhp, OcistPreprePare (stmthp, erromtpreprepare (stmthp, erromtprepreprepreprepre) Query, (UB4) Strlen (Query), (UB4) OCI_NTV_SYNTAX, (UB4) OCI_DEFAULT);

/ * Define Gid and Spatial ADT Object * / Checkerr (Errhp, OcideFineBypos (Stmthp, & DEFN1P, Errhp, (UB4) 1, (DVOID *) Global_GID, (SB4) Sizeof (OCINUMBER), SQLT_VNU, (DVOID *) 0, Ub2 *) 0, (UB2 *) 0, (UB4) OCI_DEFAULT));

Checkerr (Errhp, OcidefineBypos (Stmthp, & DEFN2P, Errhp, (UB4) 2, (DVOID *) 0, (SB4) 0, SQLT_NTY, (DVOID *) 0, (Ub2 *) 0, (UB4) ); Checkerr (errhp, ocidefineObject (defN2p, errhp, geom_tdo, (dvoid **) global_geom_obj, (ub4 *) 0, (DVOID **) global_geom_ind, (ub4 *) 0);

/ * execute * / status = ocistmtexecute (SVCHP, STMTHP, ERRHP, (UB4) Array_Size, (UB4) 0, (OCISNAPSHOT *) NULL, (OCISNAPSHOT *) NULL, (UB4) OCI_DEFAULT;

IF (status == oci_success_with_info || status == c c_no_data) HAS_MORE_DATA = FALSE; Else {HAS_MORE_DATA = true; Checkerr (Errhp, Status);

/ * Process data * / checkerr (errhp, OCIAttrGet ((dvoid *) stmthp, (ub4) OCI_HTYPE_STMT, (dvoid *) & rows_fetched, (ub4 *) 0, (ub4) OCI_ATTR_ROW_COUNT, errhp)); rows_to_process = rows_fetched - rows_processed;

Process_data (Num_Dimensions, ID_COLUMN, ROWS_TO_PROCESS, & ROWS_PROCESSED);

While (HAS_MORE_DATA) {Status = OCISTMTFETCH (Stmthp, Errhp, (UB4) Array_Size, (UB2) OCI_FETCH_NEXT, (UB4) OCI_Default);

IF (status! = OCI_Success) HAS_MORE_DATA = FALSE

/ * Process data * / checkerr (errhp, OCIAttrGet ((dvoid *) stmthp, (ub4) OCI_HTYPE_STMT, (dvoid *) & rows_fetched, (ub4 *) 0, (ub4) OCI_ATTR_ROW_COUNT, errhp)); rows_to_process = rows_fetched - rows_processed;

Process_data (Num_Dimensions, ID_COLUMN, ROWS_TO_PROCESS, & ROWS_PROCESSED);

IF (Status! = OCI_Success_With_info && Status! = OCI_NO_DATA) Checkerr (Errhp, Status);

/ ************************************************** ********************************** ROUTINE: SC_OPS_GEOM_NULL **** Description: Retruns 1 if The Geometry Object IS NULL. ******************************************************** ******************************************* / INTWREADANDWRITEMETRY:: SC_OPS_GEOM_NULL (void) {return (m_geom_ind -> _ atomic == OCI_IND_NULL);

/ ************************************************** ********************************* ROUTINE: SC_OPS_INIT_GEOMETRY **** Description: Initializaton routine. ** this must BE CALLED for a Geometry Before You Call Any ** Any Other Routines In SC_Ops ... ****************************************** *********************************************************** / voidWreadAndWriteometry :: sc_ops_init_geometry (sdo_geometry_type * geom, sdo_geometry_ind * geom_ind, int num_dimensions)

{M_geom_obj = geom; m_geom_ind = geom_ind; (! Sc_ops_geom_null ()) if {/ * Get the size of the sdo_elem_info array * / checkerr (errhp, OCICollSize (envhp, errhp, (OCIColl *) (m_geom_obj-> sdo_elem_info), & global_nelems ));

/ * Get the size of the orderinates array * / checkerr (errhp, ocicollsize (envhp, errom, (ocicoll *) (m_geom_obj-> sdo_ordinates), & global_nords));

GLOBAL_ELEM_INDEX = 0; global_first_elem = 1; global_ending_offset = -1; global_num_dimensions = num_dimensions;}}

/ ************************************************** ********************************* ROUTIPE: SC_OPS_GTNGTYPE **** Description: prints the gtype field. ** *********************************************************** ************************************** / VOIDWREADASGEMETRY:: SC_OPS_GET_GTYPE (VOID)

{INT gtype;

Checkerr (Errhp, Ocinumbertoint (Errhp, & (M_Geom_Obj-> SDO_GTYPE), (UWORD) SIZEOF (INT), OCI_NUMBER_SIGNED, (DVOID *) & gtype);

Printf ("- gtype:% d / n", gtype);

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_SDO_POINT **** Description: Prints the SDO_Point Field. ** Routine Checks for Null SDO_POINT FIELD AND ** NULL X, Y And Z Fields. ****************************************** ************************************************************************************************************************************************** :: SC_OPS_GET_SDO_POINT (VOID)

{Double X, Y, Z;

if (m_geom_ind-> sdo_point._atomic == OCI_IND_NOTNULL) {if (m_geom_ind-> sdo_point.x == OCI_IND_NOTNULL) {checkerr (errhp, OCINumberToReal (errhp, & (m_geom_obj-> sdo_point.x), (uword) sizeof (double ), (DVOID *) & x));

Printf ("- SDO_POINT.X:%. 9LF / N", X);

IF (M_Geom_ind-> SDO_POINT.Y == OCI_IND_NOTNULL) {Checkerr (Errhp, Ocinumbertoreal (Errhp, & (M_Geom_Obj-> SDO_POINT.Y), (UWORD) SIZEOF (DVOID *) & Y);

Printf ("- SDO_POINT.Y:% .9LF / N", Y);

IF (M_Geom_ind-> SDO_POINT.Z == OCI_IND_NOTNULL) {CHECKERR (Errhp, Ocinumbertoreal (Errhp, & (M_Geom_Obj-> SDO_POINT.Z), (UWORD) SIZEOF (DVOID *) & z);

Printf ("- SDO_POINT.Z:% .9LF / N", Z);}} else printf ("- sdo_point is null / n");}

/ ************************************************** ********************************* ROUTINE: SC_OPS_NEXT_ELEM **** DESCRIPTION: Go to the next element in this GEMETRY. ** RETURns 1 if there is more elements. ** Returns 0 if there is no more elements. ******************************************** *********************************************************** **** / INTWREADANDWRITEMETRY :: SC_OPS_NEXT_ELEM (Void) {INT MORE_ELEMS = 1;

IF (GLOBAL_FIRST_ELEM) GLOBAL_FIRST_ELEM = 0; ELSE GLOBAL_ELEM_INDEX = GLOBAL_ELEM_INDEX 3;

RETURN GLOBAL_ELEM_INDEX

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_ELEMENT_TYPE **** DESCRIPTION: Prints The element_type for current element. *********************************************************** ***************************************** / UB4WREADANDWRITEMETRY:: SC_OPS_GET_ELEMENT_TYPE ()

{Boolean EXISTS; OCINUMBER * OCI_NUMBER; UB4 Element_Type;

Checkerr (ErRHP, OCILLGETELEM (ENVHP, Errhp, (OCILL *) (M_Geom_Obj-> SDO_ELEM_INFO), (SB4) (GLOBAL_ELEM_INDEX 1), (Boolean *) & exists, (DVOID **) & oci_number, (dvoid **) 0) CHECKERR (Errhp, Ocinumbertoint (Errhp, OCI_Number, (UWORD) SIZEOF (UB4), OCI_Number_unsigned, (DVOID *) & Element_Type));

Printf ("- Element Type:% U / N", Element_Type); FFLUSH (STDOUT);

Return Element_Type;}

/ ************************************************** ********************************* ROUTINE: GET_INTERPRETINE: GET_INTERPRETATION **** Description: Prints The Interpretation Field for Current Element ********************************************************** ******************************** / UB4WREADANDWRITEMETRY: GET_INTERPRETATION (VOID) {Boolean EXISTS; OCINUMBER * OCI_NUMBER; UB4 Interpretation ;

Checkerr (ErRHP, OCILLGETELEM (ENVHP, Errhp, (ocicoll *) (M_Geom_Obj-> SDO_ELEM_INFO), (SB4) (Global_Elem_index 2), (Boolean *) & EXISTS, (DVOID **) & oci_number, (dvoid **) 0) );

Checkerr (Errhp, OcInumbertoint (Errhp, OCI_Number, (UWORD) SIZEOF (UB4), OCI_NUMBER_UNSIGNED, (DVOID *) & Interpretation);

Printf ("- interpretation:% u / n", interpretation; fflush (stdout);

Return interpretation;

/ ************************************************** ********************************** ROUTINE: GET_ORDINATES **** Description: Prints Ordinates Out of the Ordinates Array ********************************************************** ******************************************* / VOID WREADINATEMETRY:: GET_ORDINATES (int starting_offset, int ending_offset)

{INT col; boolean exists; ocinumber * OCI_Number; double double_val;

. / * ** Get ordinates for the current element * / for (col = starting_offset; col <= ending_offset; col ) {checkerr (errhp, OCICollGetElem (envhp, errhp, (OCIColl *) (m_geom_obj-> sdo_ordinates), (sb4 ) COL, (Boolean *) & exissrs, (DVOID **) & oci_number, (dvoid **) 0)); Checkerr (Errhp, Ocinumbertoreal (UWORD) SIZEOF (DOUBLE), (DVOID *) & Double_VAL)) ; If (COL% global_num_dimensions == 0) Printf ("%. 9LF", double_val); else printf (",% .9LF", double_val); if ((COL% global_num_dimensions) == (global_num_dimensions - 1) ) PRINTF ("/ n");} / * end for * /

Printf ("/ n");

/ ************************************************** ********************************* ROUTINE: GET_NEXT_ENDING_OFFSET **** Description: returns the ending offing offset of current Element ELEMENT ********************************************************** ****************************************** / INTWREADANDWRITEMETRY:: GET_NEXT_ENDING_OFFSET (INT processing_type_4or5)

{Boolean EXISTS; OCINUMBER * OCI_NUMBER; INT ending_offset

/ * Last element * / if (global_elem_index == global_nelems - 3) ending_offset = global_nords;? Else {checkerr (errhp, OCICollGetElem (envhp, errhp, (OCIColl *) (m_geom_obj-> sdo_elem_info), (sb4) (global_elem_index 3 ), (boolean *) & exists, (dvoid **) & oci_number, (dvoid **) 0)); checkerr (errhp, OCINumberToInt (errhp, oci_number, (uword) sizeof (int), OCI_NUMBER_SIGNED, (dvoid *) & ending_offset) );

if (processing_type_4or5) {/ * Add 1 to next elements starting offset * / ending_offset ;} else {/ * Subtract 1 from next elements starting offset * / ending_offset--;}} / * shift offsets from 1..n to 0. .n-1 * / Ending_offset

Printf ("- ending offset:% d / n", ending_offset 1);

Return Ending_offset;

/ ************************************************** ********************************* ROUTINE: GET_NEXT_STARTING_OFFSET **** Description: returns the starting offset of the current ELEMENT. ******************************************************** ********************************* / INTWREADANDWRITEMETRY:: GET_NEXT_STARTING_OFFSET (int tent_varray)

{Boolean EXISTS; OCINUMBER * OCI_NUMBER; INT Starting_offset

/ * Get the element info structure * / if (read_varray) {/ * This is the first element, get the starting offset * / checkerr (errhp, OCICollGetElem (envhp, errhp, (OCIColl *) (m_geom_obj-> sdo_elem_info), ( SB4) (global_elec_index), (Boolean *) & exissrs, (DVOID **) & oci_number, (dvoid **) 0)));

/ * Get starting and ending offsets in ordinate array * / checkerr (Errhp, OcInumbertoint (Errhp, OCI_Number, (UWORD) SIZEOF (UB4), OCI_Number_Signed, (DVOID *) & Starting_offset);

/ * Shift offsets from 1..n to 0..n-1 * / starting_offset -;} else start_offset = global_ending_offset 1; Printf ("- starting offset:% d / n", starting_offset 1);

Return starting_offset;

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_TYPE1 **** Description: Print The Ordinates for a type1 Element ********************************************************** ******************************************* / VOIDWREADANDWRITEMETRY:: SC_OPS_GET_TYPE1 (Void) {INT I, Interp, Start, End;

START = GET_NEXT_STARTING_OFFSET (GLOBAL_ENDING_OFFSET == -1); END = GET_NEXT_ENDING_OFFSET (0); Interp = Get_INTERPRETIN;

For (i = 0; I

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_TYPE2 **** Description: Print The Ordinates for a type2 Element ********************************************************** ****************************************** / VOIDWREADANDWRITEMETRY:: SC_OPS_GET_TYPE2 (VOID)

{Int interp = get_interpretation ();

GET_ORDINATES (GET_NEXT_STARTING_OFFSET (GLOBAL_ENDING_OFFSET == -1), GET_NEXT_ENDING_OFFSET (0));

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_TYPE3 **** Description: Print The Ordinates for a type3 Element ********************************************************** ****************************************** / VOIDWREADANDWRITEMETRY:: SC_OPS_GET_TYPE3 (VOID)

{INTITINT = GET_INTERPRETIN, START = GET_NEXT_STARTING_OFFSET (Global_Ending_offset == -1), end = get_next_ending_offset (0);

IF (Interp == 3) / * Rectangle, 2 Po; INTS * / GET_ORDINATES (START, START GLOBAL_NUM_DIMENSIONS * 2 - 1); ELSE IF (Interp == 4) / * Circle, 3 points * / Get_ordinates (Start, START GLOBAL_NUM_DIMENSIONS * 3 - 1);

Else if (interp == 1 || interp == 2) / * interpretation 1 or 2 * / get_ordinates (start, end);}

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_TYPE4 **** Description: Print The Ordinates for a type4 Element ********************************************************** ****************************************** / VOIDWREADANDWRITEMETRY:: SC_OPS_GET_TYPE4 (Void)

{Int interp = Get_Interpretation (), start, end, i;

for (i = 0; i

Get_ordinates (start, end);}}

/ ************************************************** ********************************* ROUTINE: SC_OPS_GET_TYPE5 **** Description: Print The Ordinates for a Type5 Element ********************************************************** ****************************************** / VOIDWREADANDWRITEMETRY:: SC_OPS_GET_TYPE5 (VOID)

{Int interp = Get_Interpretation (), start, end, i;

for (i = 0; i

Get_ordinates (start, end);}} / ************************************************* ***************************************** ROUTINE: WRITE_GEOMETRIES **** Description: *********************************************************** ***************************************************** / VOID WREADANDWRITEMETRY :: Write_Geometries () {Int i; int starting_offset = 1; Int element_type = 2; int interpretation = 1; OCINUMBER OCI_NUMBER; OCIBIND * BND1P = NULL, * BND2P = NULL; Char Query [500];

For (i = 0; i <1002; i ) {Checkerr (Errhp, OcinumberFromReal (Test_ordinates [i]), (UWORD), & OCI_Number);

Checkerr (ErRHP, OCILLAPPEND (ENVOID *) & oci_number, (dvoid *) 0, (ocicoll *) ordinates);

checkerr (errhp, OCINumberFromInt (errhp, (dvoid *) & starting_offset, (uword) sizeof (ub4), OCI_NUMBER_UNSIGNED, & oci_number)); checkerr (errhp, OCICollAppend (envhp, errhp, (dvoid *) & oci_number, (dvoid *) 0, (OCILL *) ELEM_INFO);

checkerr (errhp, OCINumberFromInt (errhp, (dvoid *) & element_type, (uword) sizeof (ub4), OCI_NUMBER_UNSIGNED, & oci_number)); checkerr (errhp, OCICollAppend (envhp, errhp, (dvoid *) & oci_number, (dvoid *) 0, (OCILL *) ELEM_INFO);

checkerr (errhp, OCINumberFromInt (errhp, (dvoid *) & interpretation, (uword) sizeof (ub4), OCI_NUMBER_UNSIGNED, & oci_number)); checkerr (errhp, OCICollAppend (envhp, errhp, (dvoid *) & oci_number, (dvoid *) 0, (OCILL *) ELEM_INFO);

Sprintf (Query, "INSERT INTO% S (GID,% s)" "VALUES (1,% s (4, NULL, NULL,: ELEM_INFO,: ORDINATES)", "Test_Insert", "Geometry", SDO_Geometry;

checkerr (errhp, OCIStmtPrepare (stmthp, errhp, (text *) query, (ub4) strlen (query), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT)); / * bind info_obj varray object * / checkerr (errhp, OCIBindByName ( Stmthp, & Bnd1p, Errhp, (Text *) ": ELEM_INFO", (SB4) -1, (DVOID *) 0, (SB4) 0, SQLT_NTY, (DVOID *) 0, (Ub2 *) 0, (UB2 *) 0, (Ub4) 0, (Ub4 *) 0, (UB4) OCI_Default); Checkerr (Errhp, OcibindObject (BND1P, Errhp, Elem_INFO_TDO, (DVOID **) & ELEM_INFO, (UB4 *) 0, (DVOID **) 0, (UB4 *) 0)); / * Bind Coordinate Varray Object * / Checkerr (Errhp, OcibindByname (stmthp, & bnd2p, errom, (text *) ": Ordinates", (SB4) -1, (DVOID *) 0 (SB4) 0, SQLT_NTY, (DVOID *) 0, (Ub2 *) 0, (Ub2 *) 0, (Ub4) 0, (Ub4 *) 0, (UB) OCI_Default); Checkerr (Errhp, OCIBIndObject) BND2P, Errhp, Ordinates_TDO, (DVOID **) & OrDinates, (Ub4 *) 0, (DVOID **) 0, (UB4 *) 0));

Checkerr (Errhp, Ocistmtexecute (SVCHP, STMTHP, Errhp, (UB4) 1, (UB4) 0, (OCISNAPSHOT *) NULL, (OCISNAPSHOT *) NULL, (UB4) OCI_DEFAULT);}

转载请注明原文地址:https://www.9cbs.com/read-120410.html

New Post(0)