Beispiel #1
0
void OWStatement::AddElement( OCIArray* poData,
                              double dfValue )
{
    OCINumber      oci_number;

    CheckError(OCINumberFromReal(hError,
        (dvoid*) &dfValue,
        (uword) sizeof(double),
        (OCINumber*) &oci_number), hError);

    CheckError(OCICollAppend(poConnection->hEnv,
        hError,
        (OCINumber*) &oci_number,
        (dvoid*) 0,
        (OCIColl*) poData), hError);
}
Beispiel #2
0
void OWStatement::AddElement( OCIArray* poData,
                              int nValue )
{
    OCINumber      oci_number;

    CheckError(OCINumberFromInt(hError,
        (dvoid*) &nValue,
        (uword) sizeof(ub4),
        OCI_NUMBER_UNSIGNED,
        (OCINumber*) &oci_number), hError);

    CheckError(OCICollAppend(poConnection->hEnv,
        hError,
        (OCINumber*) &oci_number,
        (dvoid*) 0,
        (OCIColl*) poData), hError);
}
int bingoPopRowidsToArray (OracleEnv &env, List<OraRowidText> &matched, int maxrows, OCIArray *array)
{
   OCIString *rid_string = 0;
   int count = 0;

   while (matched.size() > 0 && maxrows > 0)
   {
      const char *rid_text = matched.at(matched.begin()).ptr();

      env.callOCI(OCIStringAssignText(env.envhp(), env.errhp(), (OraText *)rid_text, (ub4)strlen(rid_text), &rid_string));
      env.callOCI(OCICollAppend(env.envhp(), env.errhp(), rid_string, 0, array));

      maxrows--;
      count++;
      matched.remove(matched.begin());
   }
   return count;
}
Beispiel #4
0
/* ODCIIndexFetch function */
OCINumber *qxiqtbspf(
OCIExtProcContext *ctx,
qxiqtim           *self,
qxiqtin           *self_ind,
OCINumber         *nrows,
short             nrows_ind,
OCIArray          **rids,
short             *rids_ind,
ODCIEnv           *env,
ODCIEnv_ind       *env_ind)
{
  sword status;
  OCIEnv *envhp = (OCIEnv *) 0;                               /* env. handle */
  OCISvcCtx *svchp = (OCISvcCtx *) 0;                      /* service handle */
  OCIError *errhp = (OCIError *) 0;                          /* error handle */
  OCISession *usrhp = (OCISession *) 0;                       /* user handle */
  qxiqtcx *icx = (qxiqtcx *) 0;         /* state to be saved for later calls */

  int idx = 1;
  int nrowsval;

  OCIArray *ridarrp = *rids;                  /* rowid collection */
  OCIString *ridstr = (OCIString *)0;

  int done = 0;
  int retval = (int)ODCI_SUCCESS;
  OCINumber *rval = (OCINumber *)0;

  ub1 *key;                                   /* key to retrieve context */
  ub4 keylen;                                 /* length of key */

  /*******************/
  /* Get OCI handles */
  /*******************/
  if (qxiqtce(ctx, errhp, OCIExtProcGetEnv(ctx, &envhp, &svchp, &errhp)))
      return(rval);

  /* set up return code */
  rval = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber));
  if (qxiqtce(ctx, errhp,
              OCINumberFromInt(errhp, (dvoid *)&retval, sizeof(retval),
                                           OCI_NUMBER_SIGNED, rval)))
    return(rval);

  /* get the user handle */
  if (qxiqtce(ctx, errhp, OCIAttrGet((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX,
                                     (dvoid *)&usrhp, (ub4 *)0,
                                     (ub4)OCI_ATTR_SESSION, errhp)))
    return(rval);

  /********************************/
  /* Retrieve context from key    */
  /********************************/
  key = OCIRawPtr(envhp, self->sctx_qxiqtim);
  keylen = OCIRawSize(envhp, self->sctx_qxiqtim);

  if (qxiqtce(ctx, errhp, OCIContextGetValue((dvoid *)usrhp, errhp,
                                             key, (ub1)keylen,
                                             (dvoid **)&(icx))))
    return(rval);

  /* get value of nrows */
  if (qxiqtce(ctx, errhp, OCINumberToInt(errhp, nrows, 
                                         sizeof(nrowsval),
                                         OCI_NUMBER_SIGNED, 
                                         (dvoid *)&nrowsval)))
    return(rval);

  /****************/
  /* Fetch rowids */
  /****************/
  while (!done)
  {
    if (idx > nrowsval)
      done = 1;
    else
    {
      status = OCIStmtFetch(icx->stmthp, errhp, (ub4)1, (ub2) 0,
                            (ub4)OCI_DEFAULT);
      if (status == OCI_NO_DATA)
      {
        short col_ind = OCI_IND_NULL;
        /* have to create dummy oci string */
        OCIStringAssignText(envhp, errhp, (text *)"dummy",
                            (ub2)5, &ridstr);
        /* append null element to collection */
        if (qxiqtce(ctx, errhp, OCICollAppend(envhp, errhp,
                                              (dvoid *)ridstr,
                                              (dvoid *)&col_ind,
                                              (OCIColl *)ridarrp)))
          return(rval);
        done = 1;
      }
      else if (status == OCI_SUCCESS)
      {
        OCIStringAssignText(envhp, errhp, (text *)icx->ridp,
                            (ub2)18, (OCIString **)&ridstr);
        /* append rowid to collection */
        if (qxiqtce(ctx, errhp, OCICollAppend(envhp, errhp, 
                                              (dvoid *)ridstr,
                                              (dvoid *)0, 
                                              (OCIColl *)ridarrp)))
          return(rval);
        idx++;
      }
      else if (qxiqtce(ctx, errhp, status))
        return(rval);
    }
  }

  /* free ridstr finally */
  if (ridstr &&
      (qxiqtce(ctx, errhp, OCIStringResize(envhp, errhp, (ub4)0,
                                           &ridstr))))
    return(rval);

  *rids_ind = OCI_IND_NOTNULL;

  return(rval);
}
Beispiel #5
0
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 );
}
Beispiel #6
0
/* 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() */