/* Function to get an array of REFs to populate the varray of REFs*/ static void getRef() { OCIDefine *defhp = (OCIDefine *) 0; /* For the REF column */ i_residence *sub_obj[NUMREC]; ub4 subsize[NUMREC]; ub4 pos = 0; ub4 arraySize = NUMREC; OCIHandleAlloc(envhp, (dvoid **) &stmthp, OCI_HTYPE_STMT, (size_t) 0, ((dvoid **) 0)); if((status = OCIStmtPrepare(stmthp, errhp, (text *) selRef, (ub4) strlen((char *) selRef), OCI_NTV_SYNTAX, OCI_DEFAULT)) != OCI_SUCCESS) { printf("OciStmtPrepare - Failure\n"); } if((status = OCIObjectNew(envhp, errhp, svchp, OCI_TYPECODE_REF, (OCIType *) 0, (dvoid *) 0, OCI_DURATION_DEFAULT, FALSE, (dvoid **) workadd)) != OCI_SUCCESS) { printf("OCIObjectNew - Failure\n"); } if((status = OCIDefineByPos(stmthp, &defhp, errhp, (ub4) 1, (dvoid *) 0, (sb4) 0, SQLT_REF, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) OCI_DEFAULT )) != OCI_SUCCESS) { printf("OCIDefineByPos - Failure\n"); } if((status = OCIDefineObject(defhp, errhp, (OCIType *) 0, (dvoid **) workadd, subsize, (dvoid **) 0, (ub4 *) 0)) != OCI_SUCCESS) { printf("OCIDefineObject - failure\n"); } if((status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) NUMREC, (ub4) 0, (OCISnapshot *) 0, (OCISnapshot *) 0, OCI_DEFAULT)) != OCI_SUCCESS) { printf("OCIStmtExecute - Failure\n"); } else { if((status = OCIObjectArrayPin(envhp, errhp, workadd, (ub4) arraySize, (OCIComplexObject **) 0, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, (dvoid **) sub_obj, (ub4 *) &pos)) != OCI_SUCCESS) { printf("OCIObjectArrayPin - Failure\n"); } } OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT); } /* End of getRef() */
void OWConnection::CreateType( OCIArray** phData, OCIType* otype) { CheckError( OCIObjectNew( hEnv, hError, hSvcCtx, OCI_TYPECODE_VARRAY, otype, (dvoid *)NULL, OCI_DURATION_SESSION, FALSE, (dvoid **)phData), hError ); }
void OWConnection::CreateType( sdo_geometry** pphData ) { CheckError( OCIObjectNew( hEnv, hError, hSvcCtx, OCI_TYPECODE_OBJECT, hGeometryTDO, (dvoid *) 0, OCI_DURATION_CALL, TRUE, (dvoid **) pphData), hError ); }
void ConvertorForRead::Fire(const BindParCollectionTabVarchar &BP, SqlCollection &SV) { sword res; SV._collection_tdo = BP._collection_tdo; SV._collection_typecode = BP._collection_typecode; SV._collection_data_type = BP._collection_data_type; SV._ind = *(sb2*)(BP._collection_indp[_row]); SV._data_type_name = BP._type_name; res = OCICALL(OCIObjectNew(BP._stmt._env, BP._stmt._errh, BP._stmt._conn._svc_ctx, OCI_TYPECODE_TABLE, // TabNum => Table BP._collection_tdo, NULL, // dvoid *table OCI_DURATION_SESSION, TRUE, // boolean value (dvoid**) &SV._valuep)); oci_check_error(__TROTL_HERE__, BP._stmt._errh, res); res = OCICALL(OCICollAssign(BP._stmt._env, BP._stmt._errh, (OCIColl*)BP.valuep[_row], SV._valuep)); oci_check_error(__TROTL_HERE__, BP._stmt._errh, res); }
sword OCI_ObjectNew ( OCIEnv *env, OCIError *err, CONST OCISvcCtx *svc, OCITypeCode typecode, OCIType *tdo, dvoid *table, OCIDuration duration, boolean value, dvoid **instance ) { sword ret = OCIObjectNew(env, err, svc, typecode, tdo, table, duration, value, instance); if (OCI_SUCCESSFUL(ret)) { OCI_MUTEXED_CALL(OCILib.nb_objinst++) } return ret; }
int main() { OGROCISession oSession; if( !oSession.EstablishSession( "warmerda", "LetoKing", "gdal800.dreadfest.com" ) ) { exit( 1 ); } printf( "Session established.\n" ); OGROCIStatement oStatement( &oSession ); oStatement.Execute( "DROP TABLE fasttest" ); oStatement.Execute( "CREATE TABLE fasttest (ifld INTEGER, cfld VARCHAR(4000), shape mdsys.sdo_geometry)" ); // oStatement.Execute( "CREATE TABLE fasttest (ifld INTEGER, cfld VARCHAR(4000))" ); /* -------------------------------------------------------------------- */ /* Prepare insert statement. */ /* -------------------------------------------------------------------- */ oStatement.Prepare( "INSERT INTO fasttest VALUES " "(:field_1, :field_2, :field_3)" ); // oStatement.Prepare( "INSERT INTO fasttest VALUES " // "(:field_1, :field_2)" ); /* -------------------------------------------------------------------- */ /* Do a conventional bind. */ /* -------------------------------------------------------------------- */ int anField1[100]; char szField2[100*4]; int anGType[100]; int anSRID[100]; OCIArray *aphElemInfos[100]; OCIArray *aphOrdinates[100]; SDO_GEOMETRY_TYPE aoGeometries[100]; SDO_GEOMETRY_ind aoGeometryIndicators[100]; SDO_GEOMETRY_TYPE *apoGeomMap[100]; SDO_GEOMETRY_ind *apoGeomIndMap[100]; double adfX[100], adfY[100]; memset( aphElemInfos, 0, sizeof(OCIArray*) * 100 ); memset( aphOrdinates, 0, sizeof(OCIArray*) * 100 ); memset( aoGeometries, 0, sizeof(SDO_GEOMETRY) * 100 ); memset( aoGeometryIndicators, 0, sizeof(SDO_GEOMETRY_ind) * 100 ); if( oStatement.BindScalar( ":field_1", anField1, sizeof(int), SQLT_INT ) != CE_None ) exit( 1 ); if( oStatement.BindScalar( ":field_2", szField2, 4, SQLT_STR ) != CE_None ) exit( 1 ); if( oStatement.BindObject( ":field_3", apoGeomMap, oSession.hGeometryTDO, (void**)apoGeomIndMap ) != CE_None ) exit( 1 ); /* -------------------------------------------------------------------- */ /* Create array of arrays for elem_info and ordinates. */ /* -------------------------------------------------------------------- */ int iBindRow; for( iBindRow = 0; iBindRow < 100; iBindRow++ ) { if( oSession.Failed( OCIObjectNew( oSession.hEnv, oSession.hError, oSession.hSvcCtx, OCI_TYPECODE_VARRAY, oSession.hElemInfoTDO, (dvoid *)NULL, OCI_DURATION_SESSION, FALSE, (dvoid **) (aphElemInfos + iBindRow)), "OCIObjectNew()") ) exit( 1 ); if( oSession.Failed( OCIObjectNew( oSession.hEnv, oSession.hError, oSession.hSvcCtx, OCI_TYPECODE_VARRAY, oSession.hOrdinatesTDO, (dvoid *)NULL, OCI_DURATION_SESSION, FALSE, (dvoid **) (aphOrdinates + iBindRow)), "OCIObjectNew()") ) exit( 1 ); } /* -------------------------------------------------------------------- */ /* Populate VARRAYs */ /* -------------------------------------------------------------------- */ int iRow; for( iRow = 0; iRow < 100; iRow++ ) { anField1[iRow] = iRow; sprintf( szField2 + iRow*4, "%3d", iRow ); anGType[iRow] = 3001; anSRID[iRow] = -1; adfX[iRow] = 100.0 + iRow; adfY[iRow] = 100.0 - iRow; //--------------------------------------------------------------- int anElemInfo[3], nElemInfoCount; OCINumber oci_number; int i; nElemInfoCount = 3; anElemInfo[0] = 1; anElemInfo[1] = 1; anElemInfo[2] = 1; // Prepare the VARRAY of ordinate values. for (i = 0; i < nElemInfoCount; i++) { if( oSession.Failed( OCINumberFromInt( oSession.hError, (dvoid *) (anElemInfo + i), (uword)sizeof(int), OCI_NUMBER_SIGNED, &oci_number), "OCINumberFromInt") ) exit( 1 ); if( oSession.Failed( OCICollAppend( oSession.hEnv, oSession.hError, (dvoid *) &oci_number, (dvoid *)0, aphElemInfos[iRow]), "OCICollAppend") ) exit( 1 ); } //--------------------------------------------------------------- double adfOrdinates[6]; int nOrdCount; nOrdCount = 3; adfOrdinates[0] = iRow + 100; adfOrdinates[1] = iRow - 100; adfOrdinates[2] = 0.0; adfOrdinates[3] = iRow + 100; adfOrdinates[4] = iRow - 100; adfOrdinates[5] = 0.0; // Prepare the VARRAY of ordinate values. for (i = 0; i < nOrdCount; i++) { if( oSession.Failed( OCINumberFromReal( oSession.hError, (dvoid *) (adfOrdinates + i), (uword)sizeof(double), &oci_number), "OCINumberFromReal") ) exit( 1 ); if( oSession.Failed( OCICollAppend( oSession.hEnv, oSession.hError, (dvoid *) &oci_number, (dvoid *)0, aphOrdinates[iRow]), "OCICollAppend") ) exit( 1 ); } // ------------------------------------------------------------- SDO_GEOMETRY_TYPE *poGeom = aoGeometries + iRow; SDO_GEOMETRY_ind *poInd = aoGeometryIndicators + iRow; poInd->sdo_point._atomic = OCI_IND_NULL; if( oSession.Failed( OCINumberFromInt( oSession.hError, (dvoid *) (anGType + iRow), (uword)sizeof(int), OCI_NUMBER_SIGNED, &(poGeom->sdo_gtype)), "OCINumberFromInt" ) ) exit( 1 ); if( oSession.Failed( OCINumberFromInt( oSession.hError, (dvoid *) (anSRID + iRow), (uword)sizeof(int), OCI_NUMBER_SIGNED, &(poGeom->sdo_srid)), "OCINumberFromInt" ) ) exit( 1 ); poGeom->sdo_elem_info = aphElemInfos[iRow]; poGeom->sdo_ordinates = aphOrdinates[iRow]; apoGeomMap[iRow] = poGeom; apoGeomIndMap[iRow] = poInd; } /* -------------------------------------------------------------------- */ /* Execute the statement. */ /* -------------------------------------------------------------------- */ int iGroup; for( iGroup = 0; iGroup < 2; iGroup++ ) { if( oSession.Failed( OCIStmtExecute( oSession.hSvcCtx, oStatement.GetStatement(), oSession.hError, (ub4) 100, (ub4)0, (OCISnapshot *)NULL, (OCISnapshot *)NULL, (ub4) OCI_COMMIT_ON_SUCCESS ), "OCIStmtExecute" ) ) exit( 1 ); } printf( "Successful completion\n" ); exit( 0 ); }
/* Function to display data from the table */ static void selectFunction () { OCIDefine *defhp = (OCIDefine *)0; OCIRef *sub_ref = (OCIRef *)0; i_manager *sub_obj = (i_manager *)0; ub4 subSize = 0; ub4 sizeUB4 = sizeof (ub4); OCIType *mtype = (OCIType *)0; OCIHandleAlloc (envhp, (dvoid **)&stmthp, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0); if ((status = OCIStmtPrepare (stmthp, errhp, (text *)selectSql, (ub4)strlen((char *)selectSql),OCI_NTV_SYNTAX, OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCIStmtPrepare - Fail\n"); } if (( status = OCIObjectNew(envhp, errhp, svchp, OCI_TYPECODE_REF, (OCIType *)0, (dvoid *)0, OCI_DURATION_DEFAULT, FALSE, (dvoid **) &sub_ref)) != OCI_SUCCESS) { printf ("OCIObjectNew - Failure\n"); } if ((status = OCIDefineByPos(stmthp, &defhp, errhp, (ub4) 1, (dvoid *) 0, (sb4) 0, SQLT_REF, (dvoid *) 0, (ub2 *)0, (ub2 *)0, (ub4) OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCIDefineByPos - Failure \n"); } if ((status = OCIDefineObject(defhp, errhp, (OCIType *) 0, (dvoid **)&sub_ref, (ub4 *)&subSize, (dvoid **) 0, (ub4 *) 0)) != OCI_SUCCESS) { printf ("OCIDefineObject - Failure \n"); } printf ("\nExecuting the statement:%s\n", selectSql); if (OCIStmtExecute (svchp, stmthp, errhp, (ub4)1, (ub4)0, (OCISnapshot *)0, (OCISnapshot *)0, OCI_DEFAULT ) != OCI_SUCCESS) { printf("OCIStmtExecute - Failure \n"); } else { printf("OCIStmtExecute - Success\n"); if ((status = OCIObjectPin(envhp, errhp, sub_ref, (OCIComplexObject *)0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, (dvoid **) &sub_obj)) != OCI_SUCCESS) { printf("OCIObjectPin - Failure \n"); } else { printf ("\nDisplaying the contents of the object\n"); display (sub_obj); } } } /* end of selectFunction() */
/* Function to modify the data of an inherited object */ static void modifyFunction () { OCIDefine *defhp = (OCIDefine *)0; OCIRef *sub_ref = (OCIRef *)0; i_residence elem; i_residence *elemptr = (i_residence *)0; i_manager *sub_obj = (i_manager *)0; ub4 subSize = 0; ub4 sizeUB4 = sizeof (ub4); OCIType *mtype = (OCIType *)0; text *name = (text*)"JENNY"; ub4 name_len=(ub4)strlen( (char * ) name); ub4 ssn = 808; /* Data for ssn */ ub4 addr_hno = 800; /*Data for hno of addr */ text *addr_street = (text *)"Laurel Road"; /*Data for street of addr */ ub4 addr_streetLen = (ub4)strlen( (char *)addr_street); ub4 altadrs_hno = 800; /*data for hno of altadrs */ text *altadrs_street = (text *)"Shoreline Street"; /*Data for street of altadrs */ ub4 altadrs_streetLen = (ub4)strlen( (char *)altadrs_street); ub4 empno = 8888; /* data for empno */ sb4 index1 = 0; /* Index for the starting point of the scan */ sb4 index2 = 0; /* Index of the next existing element */ boolean eoc = TRUE; /* For getting the status for the availability of the next index */ ub4 count = 0; /* Loop counter */ OCIHandleAlloc (envhp, (dvoid **)&stmthp, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0); if ((status = OCIStmtPrepare (stmthp, errhp, (text *)updateSql, (ub4)strlen((char *)updateSql),OCI_NTV_SYNTAX, OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCIStmtPrepare - Fail\n"); } if (( status = OCIObjectNew(envhp, errhp, svchp, OCI_TYPECODE_REF, (OCIType *)0, (dvoid *)0, OCI_DURATION_DEFAULT, FALSE, (dvoid **) &sub_ref)) != OCI_SUCCESS) { printf ("OCIObjectNew - Failure\n"); } if ((status = OCIDefineByPos(stmthp, &defhp, errhp, (ub4) 1, (dvoid *) 0, (sb4) 0, SQLT_REF, (dvoid *) 0, (ub2 *)0, (ub2 *)0, (ub4) OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCIDefineByPos - Failure \n"); } if ((status = OCIDefineObject(defhp, errhp, (OCIType *)0, (dvoid **)&sub_ref, (ub4 *)&subSize, (dvoid **) 0, (ub4 *) 0)) != OCI_SUCCESS) { printf ("OCIDefineObject - Failure \n"); } printf ("\nExecuting the statement:%s\n", updateSql); if (OCIStmtExecute (svchp, stmthp, errhp, (ub4)1, (ub4)0, (OCISnapshot *)0, (OCISnapshot *)0, OCI_COMMIT_ON_SUCCESS ) != OCI_SUCCESS) { printf("OCIStmtExecute - Failure \n"); } else { printf("OCIStmtExecute - Success\n"); if ((status = OCIObjectPin(envhp, errhp, sub_ref, (OCIComplexObject *)0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, (dvoid **) &sub_obj)) != OCI_SUCCESS) { printf("OCIObjectPin - Failure \n"); } else { printf ("\nDisplaying the original data from the employee table \n"); display (sub_obj); printf ("\nModifying the data present in the object\n"); if ((status = OCIObjectMarkUpdate (envhp, errhp, (dvoid *)sub_obj)) != OCI_SUCCESS) { printf ("OCIObjectMarkUpdate - Fail\n"); } else { printf ("OCIObjectMarkUpdate - Success\n"); } OCINumberFromInt (errhp, (dvoid *)&ssn, sizeof(ssn), OCI_NUMBER_UNSIGNED, &(sub_obj->_super.ssn)); OCINumberFromInt (errhp, (dvoid *)&empno, sizeof(empno), OCI_NUMBER_UNSIGNED, &(sub_obj->empno)); OCINumberFromInt (errhp, (dvoid *)&addr_hno, sizeof(addr_hno), OCI_NUMBER_UNSIGNED, &(sub_obj->_super.addr.hno)); OCIStringAssignText (envhp, errhp, (text *)name, (ub2)name_len, &(sub_obj->_super.name)); OCIStringAssignText (envhp, errhp, (text *)addr_street, (ub2)addr_streetLen, &(sub_obj->_super.addr.street)); OCITableFirst(envhp, errhp, (CONST OCITable*)sub_obj->_super.altadrs, &index1); OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, index1, (boolean *)&eoc, (dvoid **)&elemptr, (dvoid **)0); OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno), OCI_NUMBER_UNSIGNED, &(elemptr->hno)); OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen, &(elemptr->street)); for (count = 0; count < NUMREC-1; ++count) { altadrs_hno += count; OCITableNext(envhp, errhp, index1, (CONST OCITable*) sub_obj->_super.altadrs, &index2, &eoc); OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, index2, (boolean *)&eoc, (dvoid **)&elemptr, (dvoid **)0); OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno), OCI_NUMBER_UNSIGNED, &(elemptr->hno)); OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen, &(elemptr->street)); index1 = index2; } index1 = 0; index2 = 0; OCITableFirst(envhp, errhp, (CONST OCITable*)sub_obj->workadd, &index1); OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count], (dvoid *)0, (OCIColl *)sub_obj->workadd); for (count = 0; count < NUMREC; ++count) { OCITableNext(envhp, errhp, index1,(CONST OCITable*) sub_obj->workadd, &index2, &eoc); OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count], (dvoid *)0, (OCIColl *)sub_obj->workadd); index1 = index2; } if ((status = OCIObjectFlush(envhp, errhp, sub_obj)) != OCI_SUCCESS) { printf ("OCIObjectFlush - Fail\n"); } else { printf ("OCIObjectFlush - Success\n"); } printf ("Refreshing the object\n"); if ((status = OCIObjectRefresh(envhp, errhp, (dvoid *)sub_obj)) != OCI_SUCCESS) { printf ("OCIObjectRefresh - Fail\n"); } else { printf ("OCIObjectRefresh - Success\n"); } printf ("\nDisplaying the data in the employee table after the refresh\n"); display (sub_obj); printf ("\nModifying the data present in the object once again\n"); ssn = 606; /* Data for ssn */ addr_hno = 200; /*Data for hno of addr */ addr_street = (text *)"Main Street"; /*Data for street of addr */ addr_streetLen = (ub4)strlen( (char *)addr_street); altadrs_hno = 600; /*data for hno of altadrs */ altadrs_street = (text *)"Shell Blvd";/*Data for street of altadrs*/ altadrs_streetLen = (ub4)strlen( (char *)altadrs_street); empno = 6666; /* data for empno */ if ((status = OCIObjectMarkUpdate (envhp, errhp, (dvoid *)sub_obj)) != OCI_SUCCESS) { printf ("OCIObjectMarkUpdate - Fail\n"); } else { printf ("OCIObjectMarkUpdate - Success\n"); } index1 = 0; index2 = 0; OCINumberFromInt (errhp, (dvoid *)&ssn, sizeof(ssn), OCI_NUMBER_UNSIGNED, &(sub_obj->_super.ssn)); OCINumberFromInt (errhp, (dvoid *)&empno, sizeof(empno), OCI_NUMBER_UNSIGNED, &(sub_obj->empno)); OCINumberFromInt (errhp, (dvoid *)&addr_hno, sizeof(addr_hno), OCI_NUMBER_UNSIGNED, &(sub_obj->_super.addr.hno)); OCIStringAssignText (envhp, errhp, (text *)addr_street, (ub2)addr_streetLen, &(sub_obj->_super.addr.street)); OCITableFirst(envhp, errhp,(CONST OCITable*)sub_obj->_super.altadrs, &index1); OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, index1, (boolean *)&eoc, (dvoid **)&elemptr, (dvoid **)0); OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno), OCI_NUMBER_UNSIGNED, &(elemptr->hno)); OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen, &(elemptr->street)); for (count = 0; count < NUMREC-1; ++count) { altadrs_hno += count; OCITableNext(envhp, errhp, index1,(CONST OCITable*) sub_obj->_super.altadrs, &index2, &eoc); OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, index2, (boolean *)&eoc, (dvoid **)&elemptr, (dvoid **)0); OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno), OCI_NUMBER_UNSIGNED, &(elemptr->hno)); OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen, &(elemptr->street)); index1 = index2; } index1 = 0; index2 = 0; OCITableFirst(envhp, errhp, (CONST OCITable*)sub_obj->workadd, &index1); OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count], (dvoid *)0, (OCIColl *)sub_obj->workadd); for (count = 0; count < NUMREC; ++count) { OCITableNext(envhp, errhp, index1, (CONST OCITable*)sub_obj->workadd, &index2, &eoc); OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count], (dvoid *)0, (OCIColl *)sub_obj->workadd); index1 = index2; } if ((status = OCICacheFlush (envhp, errhp, svchp, NULL, NULL, &sub_ref)) != OCI_SUCCESS) { printf ("OCICacheFlush - Fail\n"); } else { printf ("OCICacheFlush - Success\n"); } } if ((status = OCITransCommit (svchp, errhp, OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCITransCommit - Fail\n"); } else printf ("OCITransCommit - Success\n"); } OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT); } /* end of modifyFunction() */
/* Function to insert an instance of the subtype into a supertype table */ static void insertFunction() { OCIBind *bindhp = (OCIBind *)0; i_residence elem; i_residence *elemptr = &elem; i_manager *sub_obj = (i_manager *)0; i_manager_ind ind; OCIType *i_manager_tdo = (OCIType *)0; ub4 subSize = 0; ub4 sizeUB4 = sizeof (ub4); sb4 size = 0; text *name = (text*)"JENNY"; ub4 name_len =(ub4)( strlen( (char * ) name)); ub4 ssn = 303; /* Data for ssn */ ub4 addr_hno = 33; /*Data for hno of addr */ text *addr_street = (text *)"T33"; /*Data for street of addr */ ub4 addr_streetLen = (ub4)(strlen( (char *)addr_street)); ub4 altadrs_hno = 333; /*data for hno of altadrs */ text *altadrs_street = (text *)"T333"; /*Data for street of altadrs */ ub4 altadrs_streetLen = (ub4)(strlen( (char *)altadrs_street)); ub4 empno = 3333; /* data for empno */ sb4 index1 = 0; /* Index for the starting point of the scan */ sb4 index2 = 0; /* Index of the next existing element */ boolean eoc = TRUE; /* For getting the status for the availability of the next index */ ub4 count = 0; /* Loop counter */ memset(&ind, 0, sizeof(ind)); memset(elemptr, 0, sizeof(elem)); OCIHandleAlloc (envhp, (dvoid **)&stmthp, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0); if ((status = OCIStmtPrepare (stmthp, errhp, (text *)insertSql, (ub4)strlen((char *)insertSql),OCI_NTV_SYNTAX, OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCIStmtPrepare - Fail\n"); } if ((status = OCIBindByName(stmthp, &bindhp, errhp, (text *)":v1", (sb4) -1, (dvoid *)0, (sb4)0, SQLT_NTY, (dvoid *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, OCI_DEFAULT)) != OCI_SUCCESS) { printf ("OCIBindByName - Failure \n"); } if ((status = OCITypeByName (envhp, errhp, svchp, (CONST text *)0, (ub4)0, (CONST text *)"I_MANAGER", (ub4)strlen ((char *)"I_MANAGER"), (CONST text *)0, (ub4)0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, &i_manager_tdo)) != OCI_SUCCESS) { printf ("OCITypeByName - Fail\n"); } if (( status = OCIObjectNew(envhp, errhp, svchp, OCI_TYPECODE_OBJECT, (OCIType *)i_manager_tdo, (dvoid *)0, OCI_DURATION_SESSION, TRUE, (dvoid **) &sub_obj)) != OCI_SUCCESS) { printf ("OCIObjectNew - Failure\n"); } OCINumberFromInt (errhp, (dvoid *)&ssn, sizeof(ssn), OCI_NUMBER_UNSIGNED, &(sub_obj->_super.ssn)); OCINumberFromInt (errhp, (dvoid *)&empno, sizeof(empno), OCI_NUMBER_UNSIGNED, &(sub_obj->empno)); OCINumberFromInt (errhp, (dvoid *)&addr_hno, sizeof(addr_hno),OCI_NUMBER_UNSIGNED, &(sub_obj->_super.addr.hno)); OCIStringAssignText (envhp, errhp, (text *)name, (ub2)name_len, &(sub_obj->_super.name)); OCIStringAssignText (envhp, errhp, (text *)addr_street, (ub2)addr_streetLen, &(sub_obj->_super.addr.street)); for (count = 0; count < NUMREC; ++count) { OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen, &(elemptr->street)); OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno), OCI_NUMBER_UNSIGNED, &(elemptr->hno)); if (( status = OCICollAppend (envhp, errhp, (dvoid *)elemptr, (dvoid *)&ind, (OCIColl *)sub_obj->_super.altadrs)) != OCI_SUCCESS) { printf ("OCICollAppend - Fail\n"); } altadrs_hno ++; } for (count = 0; count < NUMREC; ++count) { if (( status = OCICollAppend (envhp, errhp, (dvoid *)workadd[count], (dvoid *)&ind, (OCIColl *)sub_obj->workadd)) != OCI_SUCCESS) { printf ("OCICollAppend - Fail\n"); } } OCITableSize(envhp, errhp,(CONST OCITable*) (sub_obj->_super.altadrs), &size); OCITableSize(envhp, errhp,(CONST OCITable*) (sub_obj->workadd), &size); if (OCIBindObject(bindhp, errhp, i_manager_tdo, (dvoid **) &sub_obj, (ub4 *)0, (dvoid **)&ind , (ub4 *) 0) != OCI_SUCCESS) { printf("OCIBindObject - Failure \n"); } printf ("\nExecuting the statement:%s\n", insertSql); if (OCIStmtExecute (svchp, stmthp, errhp, (ub4)1, (ub4)0, (OCISnapshot *)0, (OCISnapshot *)0, OCI_COMMIT_ON_SUCCESS ) != OCI_SUCCESS) { printf("OCIStmtExecute - Failure \n"); } else printf("OCIStmtExecute - Success\n"); OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT); }/* End on insertFunction() */
sword _bindTextArrayTowards4D(ORACLE_SQL_CURSOR *cursor, unsigned int pos) { cursor->defines.at(pos) = 0; cursor->isObjectValid.at(pos) = false; cursor->arrayOfTexts.at(pos).resize(cursor->itemCount); cursor->indicatorLists.at(pos).resize(cursor->itemCount); cursor->lengths.at(pos).resize(cursor->itemCount); cursor->isObjectElementValid.at(pos).resize(cursor->itemCount); sessionInfo *session = _sessionGet(cursor->sessionId); for(unsigned int i = 0; i < cursor->itemCount; ++i) { PA_YieldAbsolute(); cursor->arrayOfTexts.at(pos).at(i) = 0; cursor->isObjectElementValid.at(pos).at(i) = false; sword err = 0; err = OCIObjectNew(session->envhp, session->errhp, session->svchp, OCI_TYPECODE_VARCHAR2, 0, 0, OCI_DURATION_SESSION, true, (dvoid **)&cursor->arrayOfTexts.at(pos).at(i)); if(!err) { err = OCIStringResize(session->envhp, session->errhp, BUFFER_SIZE_TEXT_ARRAY_ELEMENT, &cursor->arrayOfTexts.at(pos).at(i)); if(!err) { memset(OCIStringPtr(session->envhp, cursor->arrayOfTexts.at(pos).at(i)), 0, BUFFER_SIZE_TEXT_ARRAY_ELEMENT); cursor->isObjectElementValid.at(pos).at(i) = true; cursor->isObjectValid.at(pos) = true; cursor->lengths.at(pos).at(i) = BUFFER_SIZE_TEXT_ARRAY_ELEMENT; } } } OCIDefineByPos(cursor->stmtp, &cursor->defines.at(pos), cursor->errhp, pos + 1, &cursor->arrayOfTexts.at(pos).at(0), BUFFER_SIZE_TEXT_ARRAY_ELEMENT, SQLT_VST, &cursor->indicatorLists.at(pos).at(0), &cursor->lengths.at(pos).at(0), 0, OCI_DEFAULT); //http://docs.oracle.com/cd/A97630_01/appdev.920/a96584/oci15r34.htm return OCIDefineArrayOfStruct(cursor->defines.at(pos), cursor->errhp, sizeof(cursor->arrayOfTexts.at(pos).at(0)), sizeof(cursor->indicatorLists.at(pos).at(0)), sizeof(cursor->lengths.at(pos).at(0)), 0); //http://docs.oracle.com/cd/A97630_01/appdev.920/a96584/oci15r33.htm#498629 }